For data-cleaning purposes, I need to move punctuation (commas and periods) that occur right before certain closing tags (a
, b
,i
, strong
, em
) to the other side of those closing tags.
For example, this bit of text:
<p>Lorem ipsum dolor sit <i>amet,</i> consectetur adipiscing elit.</p>
Should be transformed into this:
<p>Lorem ipsum dolor sit <i>amet</i>, consectetur adipiscing elit.</p>
If possible, it would be neat if the RegEx could also move spaces which occur at the end of tags, though I imagine this could be accomplished by simply running the preg_replace
twice, once for spaces, and again for punctuation. For instance:
<p>Lorem ipsum dolor sit <i>amet, </i>consectetur adipiscing elit.</p>
<p>Lorem ipsum dolor sit <i>amet</i>, consectetur adipiscing elit.</p>