开发者

How to check if a char sequence isn't included in a group of char sequences using regular expressions?

开发者 https://www.devze.com 2023-02-10 04:24 出处:网络
I have to rewrite URLs which don\'t include specific words like \'contact\', \'about\', \'list\' etc. (I know it would have been easier to check for the ones for which I want t开发者_如何学Pythono do

I have to rewrite URLs which don't include specific words like 'contact', 'about', 'list' etc. (I know it would have been easier to check for the ones for which I want t开发者_如何学Pythono do the rewriting, but it's not possible in my case).

I found how to check for a single word:

^(?:(?!list).)+$

Is there a way I can verify something like:

^(?:(?!list).)+$ AND ^(?:(?!contact).)+$ AND ^(?:(?!about).)+$ AND ...   ?


^(?:(?!list|contact|about).)+$

would cover all these cases.


If you just want to match for some words in a URL, you can do this:

(list|contact|about)

If any of the words are in the url, this is true. Depending on you context, you can take the negative of this match, for example:

PHP: !preg_match("/(list|contact|about)/",$url)

mod_rewrite: RewriteRule !(list|contact|about) /404.html

Hope, this is what you need!

0

精彩评论

暂无评论...
验证码 换一张
取 消