I have a rich text editor. It generates HTML output. I want to remove last space between i
and strong
tags.
For example;
Input:
<strong>Hello World </strong>
Expected Output:
<strong>Hello World</strong>
Input:
<strong>Hello World <i>Hello Planet </i> </strong>
Expected Output:
<strong>Hello World <i>Hello Planet</i></strong>
>Solution :
/ (<\/i>|<\/strong>)/g
should be replaced with ‘$1’ as shown below:
var str = '<strong>Hello World <i>Hello Planet </i> </strong>';
var patt = / (<\/i>|<\/strong>)/g;
console.log(str.replace(patt, '$1'));
// Produces: '<strong>Hello World <i>Hello Planet</i></strong>'