In attempting some number validation, there is one case I want to exclude a number - if it contains a hyphen before the four digits.
To simplify my regular expression, let's only worry about those 4 digits.
Since I'm using JavaScript, I can't use lookbehinds.
In an attempt to use a negative lookahead to match anything not containing a hyphen, I came up with:
((?!-).)\d{4}
My test data is below, bolded are the matches:
2014
1106 **2014** **9899**
**11500**
234-233-2014
234-234-1100
-1100
Where my expectation is that 2014, 1106, 2014 and 9989 match, whereas 11500 does not. I know the issue is with the period is due to the fact that it matches anything except for line breaks. I also am trying to consider line breaks as I apply the word boundaries to my regular expression.
Might there be a better solution where I can match only a 4 digit number not followed by a hyphen, or simply exclude any matches if they are preceded by a hyphen?