Reputation: 165
I have a RegEx pattern
^(\d+|\w+-\d+)$
How do I match all those strings which do not match this pattern?
Upvotes: 2
Views: 667
Reputation: 15141
If you look into it and try to understand that. Logically it will be like this. Lets say if have a condition which say either X
or Y
then negation of its will be neither X
and nor Y
.
X or Y
negation
will be equal to Neither X and Nor Y
.
For that you can try this.
Regex: ^(?!\d+$)(?!\w+-\d+$).*$
1.
^
start of string.2.
(?!\d+$)
negative look-ahead for digits till the end of string.3.
(?!\w+-\d+$)
negative look-ahead forwords
then-
and thendigits
till the end.4.
.*$
match all till then end.
Upvotes: 3