I have got codes to match with a very simple string pattern:
XXnnnnnnnnn (2 alphanumeric, 9 numeric).
I am using this regex:
\w{2}\d{9}.
Now I am required to excude from matching any string that begins with the constant token ‘AY‘, and any string with 11 repeated character (e.g. ‘11111111111‘ or ‘00000000000‘).
How may I exlude subpatterns using regular expressions?
Try this
See it here on Regexr
Basically I added only the
\bword boundaries to your regex to avoid partial matches.Your restrictions are achieved by using negative lookahead assertions.
(?!AY)The assertion fails if the pattern starts with “AY”(?!(\w)\1{10})The assertion fails if the first word character is repeated 10 more times.Lookaround assertions on regular-expressions.info