I have a string like
str = "< p>line 1< br>< /p>< p>lin2< br>< /p>< h1>line 3< br>< /h1>";
and i need to swap < br> with their immediate next closing tags which in the above case are < /p>, < /p> and < /h1>
so final str required is:
finalStr = "< p>line 1< /p>< br>< p>lin2< /p>< br>< h1>line 3< /h1>< br>";
I tried creating regex but was not successful. Can anyone guide how in this case i can create regex and swap the occurrences of br with the next closing tags only using JS ? PS: i have added extra space in all tags so that the html editor can ignore reading them as tags