简体   繁体   English

正则表达式匹配除一个以外的所有网站

[英]Regex match all websites except for one

I am trying to create a regex query to match ALL possible websites excluding one.我正在尝试创建一个正则表达式查询来匹配除一个之外的所有可能的网站。

(https?:\/\/)?+(www)?([^:\/]+\.)?mysite\.[a-zA-Z]{1,3}

unfortunately example below will only work for search for ONLY that domain.不幸的是,下面的示例仅适用于搜索该域。

I tried adding (.mysite) but that doesn't work?我尝试添加 (.mysite) 但这不起作用? Any ideas?有任何想法吗?

Playground https://regex101.com/r/Q4QmVZ/1操场https://regex101.com/r/Q4QmVZ/1

With a negative look ahead you can exclude the domain you don't want.通过消极的展望,您可以排除您不想要的域。

\b(https?:\/\/)?(www\.)?(?!mysite)[\w-]+\.[a-z]{2,3}\b

It passes all the tests given but not sure about others.它通过了所有给定的测试,但不确定其他测试。

You can use a negative lookbehind to exclude your website and do something like this:您可以使用否定的lookbehind排除您的网站并执行以下操作:

\b(?:https?:\/\/)?(?:www\.)?[a-zA-Z0-9-]+(?<!\bmysite\b)\.[a-zA-Z]{2,4}\b

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM