Fighting with regex....
I'm using this to find pieces of HTML-string between certain elements:
for (i = 0; i < 2; i += 1) {
target = block[i]; // like BODY or HEAD
regex = RegExp('<' + target + '>(.)+</' + target + '>');
// in case string passed includes breaks/spaces
data = data.replace(/(\r\n|\n|\r)/gm,"").replace(/\s+/g," ")
.match(regex);
entry = data[0].replace(/<!-- [\s\S]*? -->/g, '');
console.log(entry);
}
While this works fine, it returns something like this:
<head>....everthing I want ....</head>
Question:
How do I need to modifiy the regex, so that I can still specifiy the element whose content I need, but which returns only the content and not content & tokens (like <head></head>
).
Thanks!