正则表达式实现 非 pattern ^((?!pattern).)+$
需求:
我希望他遇到
其他域名都匹配
答案:
^((?!(^v2ray.com$|^google\.com$|^.*\.google\.com$)).)+$
参考:
学习正则表达式规范:
https://www.runoob.com/regexp/regexp-syntax.html
测试正则表达式工具:
https://regex101.com/
https://tool.chinaz.com/regex
正则表达式"非"字符串的匹配
https://www.1kmb.com/note/160.html
思路:
"遇到 v2ray.com 本身和 google.com 及其子域名時不匹配"
= (非 v2ray.com) AND (非 google.com) AND (非 *.google.com)
= 非 (v2ray.com OR google.com OR *.google.com)
实施过程:
匹配 v2ray.com
^v2ray.com$
匹配 google.com
^google\.com$
匹配 *.google.com
^.*\.google\.com$
(v2ray.com OR google.com OR *.google.com)
(^v2ray.com$|^google\.com$|^.*\.google\.com$)
非 (pattern)
^((?!pattern).)+$
非 (v2ray.com OR google.com OR *.google.com)
^((?!(^v2ray.com$|^google\.com$|^.*\.google\.com$)).)+$
验证表达式:
在程序中验证:
v2fly/v2ray:
在加载配置文件时报错
2022/07/25 12:10:51 [Info] main/jsonem: Reading config: /usr/local/etc/v2ray/config.json
main: failed to create server > app/router: failed to build domain condition > app/router: failed to create domain matcher > error parsing regexp: invalid or unsupported Perl syntax: `(?!`
https://github.com/v2fly/v2ray-core/issues/1885
PAC 文件 via v2rayN:
正常
/^((?!(^ip.sb$|^google\.com$|^.*\.google\.com$)).)+$/
评论
发表评论