Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex: don't match if containing a specific string

Tags:

regex

I have two strings:

"Some Stuff S00E00 HDTV x264-2HD mp4"

"Some Stuff S00E00 720p HDTV X264"

And this regex:

^.ome.*.tuff.*.(mp4.*|HDTV.*|x264.*)

What I need is to only match the first one. So if the string contains "720" the regex should not match that. But the string has to contain "mp4", "HDTV" or "x264".

like image 746
arni Avatar asked Jan 13 '14 16:01

arni


1 Answers

If your chosen language / platform supports it, you can use a negative lookahead assertion, like this:

^(?!.*720).ome.*.tuff.*.(mp4.*|HDTV.*|x264.*)

But this can be further simplified to:

^(?!.*720).ome.*tuff.*(mp4|HDTV|x264).*

Demonstration

like image 69
p.s.w.g Avatar answered Sep 30 '22 01:09

p.s.w.g