"sl******@gmail.com" wrote:
I have this regex :
^*FOO([1-9]|1[0-3])
Which must to match with : 01_FOO1, 01_FOO10, 01_FOO13 and not to
01_FOO14, 01_FOO0
But this regex match with 01_FOO1 and 01_FOO14, but if i need to
01_FOO14 ( which
it'snt in the wanted range, it match because 01_FOO1 match the pattern.
How to do this ?
When you get a match against the first term in your alternation, [1-9], you
need to ensure that the following character is not a digit greater than 3.
Since you don't want (usually) to capture the following character in this
case you need to use a zero-width, negative, lookahead assertion. Something
like this:
"^.*FOO(1[0-3]|[1-9](?![0-9]))"
This says; first, try to match the 10, 11, 12, or 13. But if not, then
match any single digit as long as the character following that digit is not,
itself, a digit. Because we use a lookahead assertion, that following
character is not part of the captured text.
This should match FOO10, FOO11, FOO12, FOO13, and any of FOO1, FOO2,...,
FOO9, but not FOO0, FOO14, FOO42, etc.
Note: I'm entering this just off the top of my head, and there may be
problems with it, but I believe this is the type of approach you will need.
-- Tom