Simple, a
backreference.
Capture the first used tag, and match it later -- yes, backreferences work inside the regex, not just for replacing.
Instead of:
Use:
Code:
,</(i|b|others)></p>\s+<p><\1>
Actually, you might want to think of matching tags with attributes as well.
Code:
,</(i|b|others)></p>\s+<p( .+)?><\1>