RegEx: Not contain specific file types
I'm searching for a regular expression that hits everything that is NOT ending with ".png"
or ".jpg"
. I want to find out URLs that开发者_如何学Python do not request an image file.
I found something like this: ([^\s]+(\.(?i)(jpg|png))$)
but this is pretty much the opposite of what I want.
Is there an easy way to reverse this? Or is this expression totally wrong?!
Thanx in advance. Jan
This can be done using negative lookahead:
([^\s]+(\.(?i)(?!jpg$|png$)[^\s]+)$)
That expression will match file.gif
and file.png2
but not file.png
.
See also: Regex help. Lighttpd rewrite rule
精彩评论