How do I match all positive and negative numbers excluding 200.
I have tried the following and this regex works only for positive numbers but not for negative numbers.
^(?!(?:200)$)\d
Expected result:
0
3
199
200 this is excluded
201
-1 this should be a match
-10 this should be a match
0,3,199, and 201 match with the regex I tried
Any help is greatly appreciated.
CodePudding user response:
One way of doing it if the numbers appear at the beginning of the lines:
^(?!200\b)-?\d \b
Explanation:
^
Should be start from the beginning of the line.
(?!200\b)
200 should not come next.
-?
minus is optional.
\d
the digit itself.
\b
for word boundary. (The case @CarySwoveland mentioned in comment)