Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The regex <code>/&lt;!--[\s\S]*?--&gt;/g</code> should work.</p> <p>You're going to kill <a href="http://dev.w3.org/html5/markup/aria/syntax.html#escaping-text-span" rel="noreferrer">escaping text spans</a> in CDATA blocks.</p> <p>E.g.</p> <pre><code>&lt;script&gt;&lt;!-- notACommentHere() --&gt;&lt;/script&gt; </code></pre> <p>and literal text in formatted code blocks</p> <pre><code>&lt;xmp&gt;I'm demoing HTML &lt;!-- comments --&gt;&lt;/xmp&gt; &lt;textarea&gt;&lt;!-- Not a comment either --&gt;&lt;/textarea&gt; </code></pre> <p>EDIT:</p> <p>This also won't prevent new comments from being introduced as in</p> <pre><code>&lt;!-&lt;!-- A comment --&gt;- not comment text --&gt; </code></pre> <p>which after one round of that regexp would become</p> <pre><code>&lt;!-- not comment text --&gt; </code></pre> <p>If this is a problem, you can escape <code>&lt;</code> that are not part of a comment or tag (complicated to get right) or you can loop and replace as above until the string settles down.</p> <hr> <p>Here's a regex that will match comments including <a href="http://dev.w3.org/html5/spec-LC/tokenization.html#markup-declaration-open-state" rel="noreferrer">psuedo-comments</a> and unclosed comments per the HTML-5 spec. The CDATA section are only strictly allowed in foreign XML. This suffers the same caveats as above.</p> <pre><code>var COMMENT_PSEUDO_COMMENT_OR_LT_BANG = new RegExp( '&lt;!--[\\s\\S]*?(?:--&gt;)?' + '&lt;!---+&gt;?' // A comment with no body + '|&lt;!(?![dD][oO][cC][tT][yY][pP][eE]|\\[CDATA\\[)[^&gt;]*&gt;?' + '|&lt;[?][^&gt;]*&gt;?', // A pseudo-comment 'g'); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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