I would like to find comment tags in a string that are NOT already inside a <pre>
tag, and wrap them in a <pre>
tag.
It seems like there's no way of 'finding' comments using the PHP DOM.
I'm using regex to do some of the processing already, however I am very unfamiliar with (have yet to grasp or truly understand) look aheads and look behinds in regex.
For instance I may have the following code;
<!-- Comment 1 -->
<pre>
<div class="some_html"></div>
<!-- Comment 2 -->
</pre>
I would like to wrap Comment 1 in <pre>
tags, but obviously not Comment 2 as it already resides in a <pre>
.
How would this usually be done in RegEx?
Here's kind of what I've understood about negative look arounds, and my attempt at one, I'm clearly doing something very wrong!
(?<!<pre>.*?)<!--.*-->(?!.*?</pre>)