I have a regular expression to match URLs:
(?:开发者_如何学Go(?:http|ftp):\/\/)?[^\s]+\.[a-z]{2,}[^\s]*
Now I want to allow a specific url and variations of it.
Like www.example.com
, http://example.com/slash/slah?hello=world
.
In other means, I want my expression to not match these cases. I've been looking into look ahead and look behind, but cant really put them in place.
I thought of maybe making a regular expression to match the exceptions and replace match them with ___match
, then using the original regexp and only match if it doesn't start with ___
.
Any suggestions?
This would better be done in two steps, something like:
if ($url =~ /(?:(?:http|ftp):\/\/)?[^\s]+\.[a-z]{2,}[^\s]*/ &&
$url !~ /www.example.com|http:\/\/example.com\/slash\/slah?hello=world/)
{
...
}
(Not sure what language you're working in, this is perl code)
精彩评论