简体   繁体   English

正则表达式将一组单词列入黑名单

[英]Regular expression to blacklist a set of words

I am trying to use an api provided by another website.我正在尝试使用另一个网站提供的 api。 There is a method searchReports to which I can pass a word or a regular expression(php).有一个方法searchReports ,我可以向它传递一个词或一个正则表达式(php)。 I want to pass a regular expression for matching anything other than these words.我想传递一个正则表达式来匹配这些单词以外的任何东西。 China,Russia,North Korea . China,Russia,North Korea I tried some but nothing worked我尝试了一些但没有任何效果

^(?!(country1|country2|country3)$).*$ finally worked. ^(?!(country1|country2|country3)$).*$终于奏效了。 Thanks.谢谢。

Maybe this one:也许这个:

/^((?!(^china$)|(^russia$)|(^north korea$)).)*$/i

The "i" at the end stands for "ignore-case".最后的“i”代表“忽略大小写”。 Does php deal ok with it? php 可以处理它吗?

尝试这个

/^(?:(?!blacklisted|set|ofwords).)*\z/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM