0

I'm trying to come up with a single regex expression that matches all strings that contain "mobile" and do not contain "video" I've been struggling to do this in a single expression and would appreciate any help.

Stefan Steinegger
  • 62,367
  • 15
  • 124
  • 190

1 Answers1

4

Use the negative look-ahead assertion:

^(?!.*video).*mobile

Example:

$ cat 1.txt
audio-mobile
mobile-video
mobile-video
video-mobile
videomobile
mobile
audio-mobile
audio

$ grep -P '^(?!.*video).*mobile' 1.txt
audio-mobile
mobile
audio-mobile
Igor Chubin
  • 57,130
  • 8
  • 114
  • 135