I am working on an HTML editor in JavaScript, trying to implement an undo-feature.
So I have this HTML code (with hidden comments for storing app states):
<!-- RECONSTRUCT: 'test1' -->
<h1>FOO</h1>
<!-- END RECONSTRUCT -->
<h1>BAR</h1>
<!-- RECONSTRUCT: 'test2' -->
<h1>FOOFOO</h1>
<!-- END RECONSTRUCT -->
which I need to transform into this HTML code:
test1
<h1>BAR</h1>
test2
So basically, the html comments "save" an old state which I need to restore the code to.
So what I want a Regex to achieve is:
[0:"test1", 1:"<h1>FOO</h1>", 2:"test2", 3:"<h1>FOOFOO</h1>"]
or something similar.
The problem is, when I try to use Regex like this:
src.match(/<!-- RECONSTRUCT: '(.*)' -->(.*)<!-- RECONSTRUCT END -->/g)
I get
[0: "<!-- RECONSTRUCT: 'test1' --> ... FOO ... BAR <!-- RECONSTRUCT ... FOOFOO ... ->"]
so the complete input as an result, since its a valid match. I also don't get it working with negative look ahead:
<!-- RECONSTRUCT: '(.*)' -->((?!RECONSTRUCT:).)*