How to write a regular expression that does not match a specified word

Source: Internet
Author: User
How do I write a regular expression that does not match a specified word?
Instead of a string that has "ABC def GHI abcdef" here to specify a mismatch with ABC this word other "def Ghi abcdef" can match what I wrote/\b (?!). ABC) \w+\b/. But the problem with this is that the words beginning with ABC will not match. How should this regular expression be written?

echo preg_replace ('/\babc\b/', ', ' abc def GHI abcdef ');
Write one more step, and you'll split it with a space.

echo preg_replace ('/\babc\b/', ', ' abc def GHI abcdef ');

Don't be so troublesome ~

 $STR = ' abc def ghi abcdef ';
Preg_match_all ('/\b (?! abc\b) \w+\b/', $str, $matches);
Var_dump ($matches);

Output Result:
Array (1) {
Array (3) {
String (3) "Def"
String (3) "Ghi"
String (6) "ABCdef"
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.