I'm working on a regex that needs this format:
X = Integer
XXXX-XX
Where it only matches if follow these rules:
Here is what i have been done for each rule respectively to work:
The regex: (\d{4})-?(\d{1,2})?((?<!(\d{5})|(\d{4}-)))
(\d{4})-? and ((?<!(\d{5})|(\d{4}-))) (negative lookahead to avoid match "11111")(\d{1,2})?((?<!(\d{5})|(\d{4}-)))My problem is, i want to discard the whole string if anything is wrong.
For example
In: 123456 It matches 123456
In: 1234-5678 It matches 1234-5678
I would like to discard the whole string if it doesnt match the pattern, how can i do it?