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

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
jimiques
Forum Newbie
Posts: 2
Joined: Tue Nov 06, 2007 12:58 pm

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

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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)$
jimiques
Forum Newbie
Posts: 2
Joined: Tue Nov 06, 2007 12:58 pm

Post 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.
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Post by GeertDD »

Code: Select all

\S+\.(?!(?:gif|jpeg|html)\b)[a-z]+\b
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

negative lookahead... why didn't I think of that?

GeertDD++
Post Reply