regex - Regular Expression should not match other prefixes -
if instance have these words
- john=14
- adam=21
- ben=11
- john=18
- johan=17
- john=141
- ...
and task find occurences of john=14.
came following regular expression: .*=[^14].*\n matches every string without leading 1 after equal sign.
however, want match john=14 in example (and permutations of example). doesn't matter if there 1 or more john=14. thought negation of regular expression, such want find every string isn't equal 1 want find had problem regular expression ([^\bjohn\b=14]\n).
any appreciated :)!
you need use negative lookahead.
^(?!john=14$).* negative lookahead @ start asserts string going matched won't contain exact john=14 string. if yes match chars.
or
^(?!.*=14$).*
Comments
Post a Comment