I would like to know how to remove a single html tag from a string of html tag.
Here is an example of a string in JavaScript:
var str = "<ol class="breadcrumb>
<li>1</li>
<li>2</li>
</ol>
<div>body</div>
<ol>
<li>a</li>
</ol>"
I would like to remove the first <ol>
. Here is what I have tried:
str.replace(/\<ol class=\"breadcrumb".*\<\/ol\>/, '');
But this solution will delete everything in the string.
I have a hunch that, rather than using .*
in the above solution, I should match everything except </\ol\>
. But how can I do it, and is there an alternative solution?
Edit
I am writing a web crawler and would like to parse an HTML string.
tag inside of another
– kyasbal Aug 09 '16 at 01:01tag. Regex cannot parse collectly end tag. This is limitation of regex. That needs to use some logic with javascript.