Page 1 of 1

need a regex to match everything but GIF,JPEG and HTML files

Posted: Tue Nov 06, 2007 1:04 pm
by jimiques
Hi,

I need a regular expression that will match any filename.extension except for anything.gif, anything.jpeg, anything.html, anything.whatever_else_I_will_come_up_with (has to be expandable)

Please help

Jimiques

Posted: Tue Nov 06, 2007 1:44 pm
by Kieran Huggins
I think you need to match them and leave the negation in your PHP logic

try:

Code: Select all

\w+\.(?:html?|gif|jpe?g)$

Posted: Tue Nov 06, 2007 5:35 pm
by jimiques
It would be easy, but the problem is I'm not going to use it with PHP or some other language. The negation has to be in the regex itself.

Posted: Wed Nov 07, 2007 7:21 am
by GeertDD

Code: Select all

\S+\.(?!(?:gif|jpeg|html)\b)[a-z]+\b

Posted: Wed Nov 07, 2007 1:58 pm
by Kieran Huggins
negative lookahead... why didn't I think of that?

GeertDD++