I am trying to find a specific line that can happen inside a comment block. This line can be a word, but it can also be part of a word. For example, suppose I look for the word "codex", then this word should be replaced with "bindex", but even if it is part of the word, for example, "codexing". This should be changed to "bindexing".
The trick is that this should happen only when this word is inside the comment block.
This word --> codex should not be replaced
What I have so far is the code:
$text = preg_replace ( '~(\/\/|#|\/\*).*?(codex).*?~', '$1 bindex', $text);
As you can see in this example , this does not work as we would like. It does not replace the word when it is inside the multi-line comment block /* */ , and sometimes it deletes all the text that was before the word "codex".
How to improve my regular expression so that it matches my requirements?
source share