Please consider the following example:
let string = '<h2>Some content here</h2><p>Foo Bar</p><h2>Different content here</h2>'
I want to replace what's in between <h2>
and </h2>
.
I tried the following approach:
string.replace(/<h2.*<\/h2>/, '<h2>xxyyzz</h2>');
But the above solutions transforms string
into:
<h2>xxyyzz</h2>
Expected result:
'<h2>xxyyzz</h2><p>Foo Bar</p><h2>xxyyzz</h2>'
How can I replace what's in-between all occurrences of two substrings?