View Single Post
Quote:
Originally Posted by JKT
It would be /.\*.gif I believe (at least that is what works for .swf).
Didn't see that when reading it for the first time. It's wrong (typo?). X-)

This regex would block any URL that has in it: a slash (/) followed by any char (.) followed by an asterisk (\* - normally, an asterisk woud mean "the char before, zero or more times"; it is escaped by the backslash, though, so \* just means "one asterisk"), followed by any char (.), followed by the string "gif". I would, for example, match on the URL http://some.host.com/a*bgif/index.html - if * was allowed in URLs. ;-)

You probably meant /.*\.gif - which means: a slash (/) followed by any char (.) zero or more times (*), followed by a period (\. - this time the . is escaped and thus literally means "one period") followed by the string "gif".

This is somewhat more and also less than needed, though. Why look for the slash? There will be one already at the beginning of the URL (in http://), so it makes no sense to use it for the match. Additionally, "/.*\.gif" also matches anywhere inside the string, not only at the end. So the (hypothetical) URL "http://home.user.com/great.gifs/me.jpg" would be blocked, too.

a) You don't have to match the whole string via .* - the regex "bart" will match "bart" as well as "bartsimpson", "simpson, bart" or any other string containing "bart" anywhere inside.

b) If you want the end, use "$", which stands for "end of string" (or end of line, to be precise).

So, to match all URLs ending with ".gif", the most straightforward way will be to use "\.gif$". (A literal period (\.), followed by the string "gif" (gif), followed by the end of the string ($).)

Similarly, \.swf$ can be used to block all flash content (at least if the URL really ends with .swf, but that's the case, normally :-) ).