不包含给定的字符串的正则表达式匹配的网址字符串、不包含、网址、正则表达式

2023-09-02 09:52:14 作者:白衫学长

我需要匹配不包含任何 /管理/ ?页=

我会以此作为在iirf.ini文件重定向规则(支持htaccess的语法)。

我怎样才能做到这一点?

解决方案

使用负前瞻(?!...)用正则表达式或(A | B)

  ^(*(/管理/ |?!?页=))
 

这是说,当位于启动( ^ )的输入应包含的两个测试字符串

正则表达式,匹配以1开头的字符串,哪里有错误呢

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