Answer the question
In order to leave comments, you need to log in
Regular expressions, maximum string length
There is a regular expression: "(\d+\.)+", which describes strings like 111.223.123.12.
How can I add a check that the total length of the string, say, does not exceed twenty characters.
Thank you.
Answer the question
In order to leave comments, you need to log in
Is there any good reason not to test the condition outside of the regular expression? I can't think of an adequate way to do this right off the bat without look-behinds. Actually, they are scary.
Could you please describe the problem in its entirety? From experience, when someone asks me “how to build a regular expression” in 90% of cases, the initial statement of the problem helps to find a more adequate solution, although often through a different regular expression.
Your string 111.223.123.12 looks a lot like an ip address. It is he? Or just an example?
Why does it have to be done regularly? Can't you just check the length of a string without a regular expression?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question