tags:

views:

30

answers:

1

I have a PHP regex that I want to fail if the matched word after /blog is just feed.

This MUST be done within the regex itself, not using any other PHP syntax.

The regex currently looks like this:

blog/([a-zA-Z0-9\-]+)

What would I add to this to properly negate the regex if feed is found after blog/?

+3  A: 

Try

'/^blog\/(?!feed$)([a-zA-Z0-9-]+)$/'
S.Mark
Isn't `feed\\b` more appropriate than `feed$` in this case?
Amarghosh
@Amarghosh, you might be correct, but I wasn't sure he is matching a url or extracting urls from the text/html. So, @andybaird, If you need to extract that kind of urls from text/html data, you could remove anchors `^` and `$` s, and put `\\b` (word boundary) instead of `$`
S.Mark
Thanks Mark, I ended up implementing: blog/(?!feed\b)([a-zA-Z0-9-]+)Which worked perfectly.
Andy Baird