5

I need a pattern to match for a word and not match for another

input

black dog
black dog and gray cat

I need a pattern that match all strings that contain dog or house but it must not contain cat or girl

The first input is a match but the second is not a match

pattern

/dog|house|(?!cat|girl)/
Community
  • 1
  • 1
clarkk
  • 27,151
  • 72
  • 200
  • 340

1 Answers1

9

I think it will fill your needs

^(?!.*(cat|girl)).*(dog|house).*

Arsen
  • 10,815
  • 2
  • 34
  • 46