RegEx to move punctuation outside of tag?
<p>For data-cleaning purposes, I need to move punctuation (commas and periods) that occur right before certain closing tags (<code>a</code>, <code>b</code>,<code>i</code>, <code>strong</code>, <code>em</code>) to the other side of those closing tags.</p>

<p>For example, this bit of text:</p>

<pre><code>&lt;p&gt;Lorem ipsum dolor sit &lt;i&gt;amet,&lt;/i&gt; consectetur adipiscing elit.&lt;/p&gt;
</code></pre>

<p>Should be transformed into this:</p>

<pre><code>&lt;p&gt;Lorem ipsum dolor sit &lt;i&gt;amet&lt;/i&gt;, consectetur adipiscing elit.&lt;/p&gt;
</code></pre>

<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 <code>preg_replace</code> twice, once for spaces, and again for punctuation. For instance:</p>

<pre><code>&lt;p&gt;Lorem ipsum dolor sit &lt;i&gt;amet, &lt;/i&gt;consectetur adipiscing elit.&lt;/p&gt;
&lt;p&gt;Lorem ipsum dolor sit &lt;i&gt;amet&lt;/i&gt;, consectetur adipiscing elit.&lt;/p&gt;
</code></pre>