I'm trying to create a regular expression where it replaces words which are not enclosed by brackets.
Here is what I currently have:
$this->parsed = preg_replace('/\b(?<!\[)('.preg_quote($word).')\b/','[$1['.implode(",",array_unique($types)).']]',$this->parsed);
Where $word could be one of the following, "Burkely Mayfair Trunk" or "Trunk".
It would replace the sentence
This Burkely Mayfair Trunk is pretty nice
for
This [Burkely Mayfair [Trunk[productname]][productname]] is pretty nice
Although it should become
This [Burkely Mayfair Trunk[productname]] is pretty nice
Since it replaces in order of the largest string to the smallest string, the smaller strings and or double occurences of word parts should not be replaced in an already replaced part of the string. It works when it's the first part of the string.
When I try to make a dynamic lookbehind it gives the following error: "Compilation failed: lookbehind assertion is not fixed length at offset 11". And I have no idea on how to fix this.
Anyone who has any ideas?