Original version:
<div>
<p>
<span>text</span>
</p>
<div>
RegExp:
$.get('/some.html', function(data) {
alert(data.replace(/<p.*p>/gi, ''));
});
After RegExp:
<div>
<>
<span>text</span>
</>
<div>
What do I need to get:
<div>
<div>
Javascript has no dotall mode so your
.does not match newline characters.but you can try this
[\S\s]means match any non whitespace (\S) or any whitespace (\s) character. the newline characters are included in the whitespace characters.The
*?is a non greedy match, means it matches as less as possible.As soon as your tags are nested, you will run into problems when using regular expressions. You have to be aware of that. Probably the solution from @fearofawhackplanet is the better choice.