3

I want to test for strings that do not contain a particular sub string

Examples strings are:

event2
event23,event1,event67=12
event1,event30
event23
event2
event2,event23

I want to match strings that do not contain event2.

Therefore the following strings should match:
event23,event1,event67=12
event1,event30
event23

So far I can match strings the do contain event2 with the following expression:
/^.*(\bevent2\b)/gm

But I don't know how to combine this with a negative lookahead.

This doesn't seem to work:
/^.*(?!.*(\bevent2\b))/gm

eLRuLL
  • 18,488
  • 9
  • 73
  • 99
megatron77
  • 221
  • 1
  • 8
  • 18

1 Answers1

5

You could use a negative lookahead:

^(?!.*event2\b).*$

The fourth bird
  • 154,723
  • 16
  • 55
  • 70