Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get the Regex Groups for a given Capture?
    primarykey
    data
    text
    <p>I'm parsing CSS3 selectors using a regex. For example, the selector <code>a&gt;b,c+d</code> is broken down into:</p> <pre><code> Selector: a&gt;b c+d SOSS: a b c d TypeSelector: a b c d Identifier: a b c d Combinator: &gt; + </code></pre> <p>The problem is, for example, I don't know which selector the <code>&gt;</code> combinator belongs to. The <code>Selector</code> Group has 2 captures (as shown above), each containing 1 combinator. I want to know what that combinator is for that capture.</p> <p>Groups have lists of Captures, but Captures don't have lists of Groups found in that Capture. Is there a way around this, or should I just re-parse each selector?</p> <hr> <p><strong>Edit:</strong> Each capture does give you the index of where the match occurred though... maybe I could use that information to determine what belongs to what?</p> <hr> <p>So you don't think I'm insane, the syntax is actually quite simple, using my special dict class:</p> <pre><code>var flex = new FlexDict { {"GOS"/*Group of Selectors*/, @"^\s*{Selector}(\s*,\s*{Selector})*\s*$"}, {"Selector", @"{SOSS}(\s*{Combinator}\s*{SOSS})*{PseudoElement}?"}, {"SOSS"/*Sequence of Simple Selectors*/, @"({TypeSelector}|{UniversalSelector}){SimpleSelector}*|{SimpleSelector}+"}, {"SimpleSelector", @"{AttributeSelector}|{ClassSelector}|{IDSelector}|{PseudoSelector}"}, {"TypeSelector", @"{Identifier}"}, {"UniversalSelector", @"\*"}, {"AttributeSelector", @"\[\s*{Identifier}(\s*{ComparisonOperator}\s*{AttributeValue})?\s*\]"}, {"ClassSelector", @"\.{Identifier}"}, {"IDSelector", @"#{Identifier}"}, {"PseudoSelector", @":{Identifier}{PseudoArgs}?"}, {"PseudoElement", @"::{Identifier}"}, {"PseudoArgs", @"\([^)]*\)"}, {"ComparisonOperator", @"[~^$*|]?="}, {"Combinator", @"[ &gt;+~]"}, {"Identifier", @"-?[a-zA-Z\u00A0-\uFFFF_][a-zA-Z\u00A0-\uFFFF_0-9-]*"}, {"AttributeValue", @"{Identifier}|{String}"}, {"String", @""".*?(?&lt;!\\)""|'.*?(?&lt;!\\)'"}, }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    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