Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just in case you won't succeed in finding a sufficient regex, may I suggest a JavaScript parser generator like <a href="http://pegjs.majda.cz/" rel="nofollow">PEG.js</a>*. There's an <a href="http://pegjs.majda.cz/online" rel="nofollow">online version</a> of PEG.js that allows you to tinker with the grammar, then download the parser once satisfied with the result.</p> <p>[ * ] PEG - <a href="http://en.wikipedia.org/wiki/Parsing_expression_grammar" rel="nofollow">Parsing Expression Grammar</a></p> <p>For help with the grammar you should consult the <strike><a href="http://www.w3.org/TR/css3-syntax" rel="nofollow">W3C's working draft on CSS3 syntax</a></strike> <a href="http://www.w3.org/TR/css3-selectors/#w3cselgrammar" rel="nofollow">W3C's recommendation on Selectors Level 3</a>.</p> <p>I took the time and played around and came up with a reduced grammar for a single selector (element/id/attr/class/pseudo). You'd want to go over it and refine it here and there, probably.</p> <pre><code>/* * PEG.js grammar */ start = element? hash? (class / attr / pseudo)* element = '*' / ident ident = i:(nmstart) j:(nmchar*) {return i + j.join('');} hash = h:('#' ident) {return h.join('');} class = c:('.' ident) {return c.join('');} attr = a:('[' (b:[^\]]+ {return b.join('');}) ']') {return a.join('');} pseudo = p:(':' function) {return p.join('');} nmstart = [a-z] / nonascii nmchar = [a-z0-9-] / nonascii function = f:(ident '(' body ')') {return f.join('');} body = b:[^\)]+ {return b.join('');} nonascii = [\x80-\xff] _ = [ \t\n\r]+ {return '';} </code></pre>
 

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