Reputation: 186
I have two urls (below). I need to match the one that doesn't contain the "story" part in the it. I know i need to use negative lookhead/behind, but i cant for the life of me get it to work
Urls
news/tech/story/2014/oct/28/apple-iphone/261736
news/tech/2014/oct/28/apple-iphone/261736
Current Regex
news\/([a-z0-9-\/]{1,255})(\d{4})\/(\w{3})\/(\d{2})\/([a-z0-9\-]{1,50})\/(\d{1,10})
Example:
http://regex101.com/r/jC7jC4/1
Upvotes: 1
Views: 60
Reputation: 947
you can try this one :
news\/(([a-z0-9-\/](?!story)){1,255})(\d{4})\/(\w{3})\/(\d{2})\/([a-z0-9\-]{1,50})\/(\d{1,10})
Upvotes: 1
Reputation: 2428
You can check with strpos() if you don't have to use regex
if (strpos($url, 'story') === false
Upvotes: 1
Reputation: 784998
You can use negative lookahead like this:
(?!.*\bstory\b)news\/([a-z0-9-\/]{1,255})(\d{4})\/(\w{3})\/(\d{2})\/([a-z0-9\-]{1,50})\/(\d{1,10})
(?!.*\bstory\b)
is negative lookahead that will stop match if there is a word story
in the URL.
Upvotes: 1