Jump to content
Ketarin forum

Quick Regex Query


Omniferum
 Share

Recommended Posts

I've been trying to find a way to exclude a specific word from my regex matches, in this case the word source.

 

My current 'attempt' has only found to be working if the word source or src is found to happen right BEFORE the extension. I assume it is because of the characters in the square brackets? Either way I was just curious if anyone could just spot what I needed doing and give me the (no doubt) 4 extra characters required to make it exclude matches with a specified word.

 

http[^'"]+64[^'"]+7z

 

Now if I do

 

http[^'"]+64[^'"source]+7z

 

It will work, only if the filename ends like vrasr444source.7z

 

I obviously want it to apply to the entire match, not just the position.

Link to comment
Share on other sites

Actually, the way that regex will work is to eliminate any URL where any of the characters "ceorsu" appear between "64" and "7z". The [^] pattern excludes those characters, NOT in any specific order/sequence. Simple regex really isn't good for excluding long strings/sequences like that. Some implementations (this one should) provide what's called "negative lookahead", which effectively excludes a string from a pattern. The following will capture a string that does NOT contain "IgnoreMe".

(?!IgnoreMe)

 

http://msdn.microsoft.com/en-us/library/ms972966.aspx

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.