I'm trying to write a regex that will remove HTML tags around a placeholder text, so that this:
<p>
Blah</p>
<p>
{{{body}}}</p>
<p>
Blah</p>
Becomes this:
<p>
Blah</p>
{{{body}}}
<p>
Blah</p>
My current regex is /<.+>.*\{\{\{body\}\}\}<\/.+>/msU
. However, it will also remove the contents of the tag preceding the placeholder, resulting in:
{{{body}}}
<p>
Blah</p>
I can't assume the users will always place the placeholder inside <p>
, so I would like it to remove any pair of tags immediately around the placeholder. I would appreciate some help with correcting my regex.
[EDIT]
I think it's important to note that the input may or may not be processed by CKEditor. It adds newlines and tabs to the opening tags, thus the regex needs to go with the /sm
(dotall + multiline) modifiers.