否定正则表达式的匹配结果

Negate matched results of regex expression

我想提出一个正则表达式来否定正则表达式的匹配结果:.google.*search。并且,是否可以使用我试图否定的正则表达式中的正则表达式来实现它?

测试数据

[1] https://www.google.com/search?newwindow=1&sxsrf=ALeKk02MzEfbUp3jO4Np
[2] https://github.com/redis/redis-rb
[3] https://web.whatsapp.com/

预期结果

第 2、3 行匹配正则表达式模式,是结果的一部分。

以下 regex 可以解决问题

^(?!.+google.*search)

基本上匹配行的开头然后取反 (?!)(否定前瞻)你的正则表达式。

你可以在这里使用负前瞻:

https?:\/\/(?!.*\.google\..*search).*

Demo

这里的“秘密武器”是 (?!.*\.google\..*search),它断言 .google. 后跟 search 不会出现在 URL 内的任何地方 URL =14=]部分。