RegEx: Not contain specific file types - regex

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 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

Related

RegEx match all website links except those containing admin

I'm setting up URL Rewrite on an IIS and i need to match the following URLs using regex.
http://sub.mysite.com
sub.mysite.com
sub.mysite.com/
sub.mysite.com/Site1
sub.mysite.com/Site1/admin
but not:
sub.mysite.com/admin
sub.mysite.com/admin/somethingelse
sub.mysite.com/admin/admin
The site it self (sub.mysite.com) should not be "hardcoded" in the expression. Instead, it should be matched by something like .*.
I'm really blank on this one. I did find solutions to match the different URLs but once i try to combine them either none of them match or all of them do.
I hope someone can help me.
For your specific case, assuming you are matching the part after the domain (REQUEST_URI):
(?!/admin).*
(?!...) is a negative lookahead. I am not sure if it is supported in the IIS URL Rewrite engine. If not, a better approach would be to check for a complementary approach:
Or as #kirilloid said, just match /admin/? and discard (pay attention to slashes).
BTW. if you want to quickly test RegExps with a "visual" feedback, I highly recommend http://gskinner.com/RegExr/
([A-Za-z0-9]+.)+.com(?!/admin)/?([A-Za-z0-9]+/?)*
this should do the trick

Filtering specific word form sentence by regex

I am trying to make a regular expression which will give an error when user will give specific input like feat, ft. I do want to allow this kind of input in a sentence. How can I solved this problem.
For example:
The feat-incorrect
featable-corroct
rahin (feat)-incorrect
feat-incorrect
I create one
regex: /^(?!.(feat|artists|Diverse artister|Feat|Feat.Featuring)).$/
in this regex
featable- is incorrect. But I need this one correct
has Anyone solved this kind of problem? Thanks in advance.
If your question is how to create a REGEX that selects whole words and not part of a word then try something like this:
\bfeat\b
If you want the only correct word to be featable then use \bfeatable\b
check out this Regex Expression builder, its useful. the builder would highlight the correct words for the expression you put.

Regular Expression for recognizing files with following patterns az.4.0.0.119.tgz

I am trying to find a regular expression that will recognize files with the pattern as az.4.0.0.119.tgz. I have tried the regular expression below:
([a-z]+)[.][0-9]{0,3}[.][0-9]{0,3}[.][0-9]{0,3}[.]tgz
But, no luck. Can anyone please point me in the right direction.
Regards,
Shreyas
Better to use a simple regex like this:
^([a-z]+)\.(?:[0-9]+\.)+tgz$
You just forgot one number part:
([a-z]+)[.][0-9]{0,3}[.][0-9]{0,3}[.][0-9]{0,3}[.][0-9]{0,3}[.]tgz
or
([a-z]+)[.]([0-9]{0,3}[.]){4}tgz
Depending on where and how you use the regex, you might want to surround it in ^...$.
Your pattern has 4 chiffers group, your regexp only 3.

Regex Expression to Match URL and Exclude Other

Im trying to write a regex expression to match anything (.*)/feed/ with the exception of (.*)/author/feed/
Currently, I have (.*)/feed/(.*) which works well to identify any string /feed/ to redirect. However, I dont want to exlude those that have /author/(.*)/feed/
For example - match http://www.site.com/ANYTHING/feed/ but exclude site.com/author/ANYTHING/feed/
I should clarify that I'm not terribly familiar with regex expressions but this is actually for use within the Redirection plugin for wordpress which states "Full regular expression support."
Any help would be greatly appreciated. Thank you in advance
Depending on the language, you may be able to use a negative look-behind assertion:
(.*)(?<!/author)/feed
The assertion, (?<!/author), ensures that /author does not match behind the text /feed, but does not count it as being matched.

Regular Expression Lookbehind and Lookahead numerical test

I am attempting to configure a regular expression that matches anything numerical value but 1211 so it will still match variations such as 1212 121 1122, 3411, etc
I am unable to test the below at http://regexpal.com/ as it does not seem to support ?
(1(?!2)|1(?!2)|(?<!1)2|(?<!2)1|[^1211])+|[0-9]{1,4})
Am I doing it right and also where can I test it?
EDIT
Please note that I need to implement in a rewrite module/filter.
You can simplify that regex a lot:
^(?!1211)[1-9]\d{0,3}$
As for regexpal, it's not working because your regex is invalid. You can tell right away because it as one more closing parenthesis than opening.
I suggest you take a simple route:
if (data != "1211"){
// your other regex here
}
you can test it using javascript, if you are familiar with it.