PDA

View Full Version : Regex match string1 but not string2 - help please



lonewolf
16 May 2007, 04:00 AM
Its probably really easy, but I have not been able to crack this one.

I need a regex for AWStats that will match in the URL /blog but not /feed. I can match every occurrence of /blog or every line that does not contain /feed, but not both together.

e.g.
/blog/category/uebgrsekbgisuebgr/erthsrth/4/ WILL match
/blog/feed/atom will NOT match
/blog/2007/05/13 WILL match
/blog/feed will NOT match
/blog WILL match

So far I have:


^/blog/([^feed])

But that's not matching anything.

I have been using Regulazy (http://tools.osherove.com/Default.aspx?tabid=182) to build and test my regex, as well as testing within AWStats.


Please could somebody help me with this expression.

Thanks in advance

Tim

Saj
24 May 2007, 11:49 AM
I'm not great at regex, so forgive me if this is buggy. It works with all the scenarios you gave though:


/blog/?([^(feed)]{4}).*

Hope that at least gets you on the right track ;)