I'm trying to split my string that represents html markup so that <ul>
tags end up as a separate index in the resulting array. I've created the following regex which seems to work for finding <ul>...</ul>
:
/(<ul>.*?<\/ul>)/i
I know it works because I tested it here: https://regex101.com/r/DNAHzr/2
However, as seen in the snipped below, the string split()
doesn't seem to actually split my markdown on the given regex:
var body = "soupp\n\nWhat a bloody nice video!! :)) {{youtube:hyYnAioXOqQ}}\n\nSuppp\n\n<ul>\n<li>1\n</li>\n<li><b>2</b>\n</li>\n</ul>\n{{attachment:2938222}}\n\n<ul>\n<li>1\n</li>\n<li>2\n</li>\n</ul>\n<ol>\n<li>bruhh\n</li>\n<li>twotwo\n</li>\n</ol>"
var comps = body.split(/(<ul>.*?<\/ul>)/i).filter(x => !!x);
console.log(comps);
Can anybody help me get my method to work properly?
` tags and remove the newlines inside of those.
– MarksCode Sep 07 '17 at 18:32