开发者

URL regular expression exluding specifik domain

开发者 https://www.devze.com 2023-01-31 16:03 出处:网络
I have a regular expression to match URLs: (?:开发者_如何学Go(?:http|ftp):\\/\\/)?[^\\s]+\\.[a-z]{2,}[^\\s]*

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消