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.
Asked
Active
Viewed 94 times
0
-
What language are you trying to do this in? – twmb Aug 08 '12 at 15:04
-
I'm trying to do this in bash – user1382685 Aug 08 '12 at 15:09
1 Answers
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