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
  • 63,782
  • 15
  • 129
  • 193
user1382685
  • 49
  • 1
  • 5

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
  • 61,765
  • 13
  • 122
  • 144