I guess this is simple, but I'm struggling with the following situation:
String (HTML passed as text):
text<br>text<br><ul><li>text</li></ul><br>
Now I need to replace each text<br>
with <div>text</div>
Unless the text is within <li>/<ul>
.
.replace(/(.*?)<br>/g, '<div></div>')
This works fine, but how do I prevent <ul><li>text</li></ul><br>
from being replaced?
"You cannot parse [HTML] using regular expressions. [...] Have you tried using [HT]ML instead with a parser? "™
(A more concise version can be found in the code snippet below)
try it:
'; console.log(replaceTextBrWithDiv(content));
Here's my attempt before going for a (shorter) regex solution: