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?
------Solution--------------------
echo preg_replace ('/\babc\b/', ', ' abc def GHI abcdef ');
------Solution--------------------
Write one more step, and you'll split it with a space.
------Solution--------------------
References:
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) {
[0]=>
Array (3) {
[0]=>
String (3) "Def"
[1]=>
String (3) "Ghi"
[2]=>
String (6) "ABCdef"
}
}