this is a follow up after reading How to specify "Space or end of string" and "space or start of string"?
From there, it states means to match a word in a phrase. I can even add a few other solutions. But as soon as a = or " is added, it quit working. Why?
i am going to search for stackoverflow and replace it with OK using preg_replace()
preg_replace('/\bstackoverflow\b/', 'OK', $input_line)
input:
1: stackoverflow xxx
2: xxx stackoverflow xxx
3: xxx stackoverflow
result:
1: OK xxx
2: xxx OK xxx
3: xxx OK
now, if i change it to match stackoverflow="", it stops working.
preg_replace('/\bstackoverflow=""\b/', 'OK', $input_line)
input:
1: stackoverflow="" xxx
2: xxx stackoverflow="" xxx
3: xxx stackoverflow=""
result:
1: stackoverflow="" xxx
2: xxx stackoverflow="" xxx
3: xxx stackoverflow=""
the same will happen if i use on my regex: /\bstackoverflow=\b/ or /\bstackoverflow"\b/. I already checked the manual if = or " are special chars, they are not. but i even tried /\bstackoverflow\=\"\"\b/
Why is that?
in that example removing \b will also solve it, but it will also match nostackoverflow=""not which i do not want.
i also tried alternatives to \b such as [ ^] and ( |^). Interestingly [ ^] (space or beginning of line) will not work for beginning of line, only space. But ( |^) will work fine for both.
 
     
     
    