The pattern below seems to work in regex editors, but it doesn’t work in PHP (no error).
I thought by adding delimiters and running the pattern through preg_quote would address this.
Would appreciate any help on what step I’m missing here.
Code sample:
$pattern = '%(?<=@address|.)singleline(?=[^\]\[]*\])%';
$pattern = preg_quote($pattern);
$output = preg_replace($pattern, "", $output);
HTML Sample:
<p>[@address|singleline]</p>
preg_quoteescapes characters that are regular expression syntax characters. These include. \ + * ? [ ^ ] $ ( ) { } = ! < > | : -. Try not usingpreg_quote.EDIT:
You might want to use
preg_quoteif you had content you wanted to include in your regex pattern which contained characters used in regex syntax. For example:In this case, you need to escape the
$because it is used in the regex syntax. To search for it, your regex should use\$instead of$. Using preg_quote performs this alteration for you.