Note that there are some explanatory texts on larger screens.

plurals
  1. POCan you provide some examples of why it is hard to parse XML and HTML with a regex?
    text
    copied!<p>One mistake I see people making <a href="https://stackoverflow.com/questions/699708/variable-order-regex-syntax">over</a> and <a href="https://stackoverflow.com/questions/457015/regular-expression-help">over again</a> is trying to parse XML or HTML with a regex. Here are a few of the reasons parsing XML and HTML is hard:</p> <p>People want to treat a file as a sequence of lines, but this is valid:</p> <pre><code>&lt;tag attr="5" /&gt; </code></pre> <p>People want to treat &lt; or &lt;tag as the start of a tag, but stuff like this exists in the wild:</p> <pre><code>&lt;img src="imgtag.gif" alt="&lt;img&gt;" /&gt; </code></pre> <p>People often want to match starting tags to ending tags, but XML and HTML allow tags to contain themselves (which traditional regexes cannot handle at all):</p> <pre><code>&lt;span id="outer"&gt;&lt;span id="inner"&gt;foo&lt;/span&gt;&lt;/span&gt; </code></pre> <p>People often want to match against the content of a document (such as the famous "find all phone numbers on a given page" problem), but the data may be marked up (even if it appears to be normal when viewed):</p> <pre><code>&lt;span class="phonenum"&gt;(&lt;span class="area code"&gt;703&lt;/span&gt;) &lt;span class="prefix"&gt;348&lt;/span&gt;-&lt;span class="linenum"&gt;3020&lt;/span&gt;&lt;/span&gt; </code></pre> <p>Comments may contain poorly formatted or incomplete tags:</p> <pre><code>&lt;a href="foo"&gt;foo&lt;/a&gt; &lt;!-- FIXME: &lt;a href=" --&gt; &lt;a href="bar"&gt;bar&lt;/a&gt; </code></pre> <p>What other gotchas are you aware of?</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