-1

I want to replace the empty tag (same tag name) such as:

 <i>12341234</i><b></b> to <i>12341234</i>

and also:

 <b>1234</b><b>5678</b> to <b>12345678</b>

Thank you very much!!!

Huy282002
  • 71
  • 1
  • 5
  • https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – Teemu Nov 07 '22 at 07:55
  • Merging sequential inline elements is OK (with a ton of exceptions), but doing so with block elements breaks the page. It looks like you've to create your own "parser" of the live code, which makes difference between inline and block elements (which is not easy, as you can convert an inline element to a block element with CSS). You can use the built-in parsers browser provides. For starters, take a look at [DocumentFragment](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment). – Teemu Nov 07 '22 at 08:10

1 Answers1

1

For the first line:

<([^\<\>/]+)></\1>

For the second line:

</([^\<\>]+)><\1>

And you replace the matched characters by nothing to remove them. In addition, you can limit the number of characters inside the tag like this (5 in this case):

<([^\<\>/]{1,5})></\1>