Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript regex not containing keyword with backslashes
    text
    copied!<p>I'm having a problem with a javascript regex that has to comment out all tags inside a script tag. But it can not comment out special first script tag with id "ignorescript".</p> <p>Here is a sample string to regex:</p> <pre><code>&lt;script id="ignorescript"&gt; var test = '&lt;script&gt;test&lt;\/script&gt;; var xxxx = 'x'; &lt;/script&gt; </code></pre> <p>Script tag inside ignorescipt has extra backslash because it is JSON encoded (from PHP).</p> <p>And here is the final result i have to get:</p> <pre><code>&lt;script id="ignorescript"&gt; var test = '&lt;!ignore-- &lt;script&gt;test&lt;\/script&gt; ignore--&gt;; var xxxx = 'x'; &lt;/script&gt; </code></pre> <p>Following example works:</p> <pre><code>content = content.replace(/(&lt;script&gt;.*&lt;\\\/script&gt;)/g, "&lt;!--ignore $1 ignore--&gt;"); </code></pre> <p>But I need to check that it does not contain a keyword "ignorescript". If that keyword comes up then I do not want to replace anything. Otherwise add ignore comments to whole script tag So far I have gotten this far:</p> <pre><code>content = content.replace(/(&lt;script.((?!ignorescript).)*&lt;\/script&gt;)/g, "&lt;!--ignore $1 ignore--&gt;"); </code></pre> <p>It kinda works, but not the way it supposed to be. I also have one more backslash in ending tag. So I changed it to:</p> <pre><code>content = content.replace(/(&lt;script.((?!ignorescript).)*&lt;\\\/script&gt;)/g, "&lt;!--ignore $1 ignore--&gt;"); </code></pre> <p>Not it does not find anything at all.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload