不包含给定的字符串的正则表达式匹配的网址 [英] regex match urls NOT containing given set of strings
本文介绍了不包含给定的字符串的正则表达式匹配的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要匹配不包含任何 /管理/
或?页=
。所有网址P>
我会以此作为在iirf.ini文件重定向规则(支持htaccess的语法)。
我怎样才能做到这一点?
解决方案
使用负前瞻(?!...)
用正则表达式或(A | B)
:
^(*(/管理/ |?!?\页=))
这是说,当位于启动( ^
)的输入应包含的两个测试字符串
I need to match all urls that DO NOT contain either /admin/
or ?page=
.
I'll be using this as a redirect rule in an iirf.ini file (supports htaccess syntax).
How can I accomplish this?
解决方案
Use a negative look-ahead (?!...)
with a regex OR (a|b)
:
^(?!.*(/admin/|\?page=))
This is saying that when positioned at the start (^
) the input should contain either of your two test strings
这篇关于不包含给定的字符串的正则表达式匹配的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文