Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression to blacklist a set of words

Tags:

regex

php

I am trying to use an api provided by another website. There is a method searchReports to which I can pass a word or a regular expression(php). I want to pass a regular expression for matching anything other than these words. China,Russia,North Korea . I tried some but nothing worked

like image 597
haseeb Avatar asked Oct 28 '25 03:10

haseeb


3 Answers

^(?!(country1|country2|country3)$).*$ finally worked. Thanks.

like image 135
haseeb Avatar answered Oct 29 '25 16:10

haseeb


Maybe this one:

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

The "i" at the end stands for "ignore-case". Does php deal ok with it?

like image 43
marcellorvalle Avatar answered Oct 29 '25 18:10

marcellorvalle


^(?!(country1|country2|country3)$).*$ finally worked. Thanks.

like image 43
haseeb Avatar answered Oct 29 '25 18:10

haseeb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!