It\'s a simple question about regular expressions, but I\'m not finding the answer.
I want to determine whether a number appears in sequence exactly two
(?
This is the correct way to do it. The accepted answer is wrong.
It would match 3 digits (or 5). So that is wrong in my eyes.
1) Check there is no digit before a sequence of 2, or 4 digits, or after a sequence of two or four digits.
( syntax is negative lookbehind
(?!) syntax is negative lookahead.
The above would work for mid string:
If your search string has no content around it you could use the ^ and $ start and end of string anchors:
^\d{4}$|^\d{2}$