Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Every regex flavor I know numbers groups by the order in which the opening parentheses appear. That outer groups are numbered before their contained sub-groups is just a natural outcome, not explicit policy.</p> <p>Where it gets interesting is with <em>named groups</em>. In most cases, they follow the same policy of numbering by the relative positions of the parens--the name is merely an alias for the number. However, in .NET regexes the named groups are numbered separately from numbered groups. For example:</p> <pre><code>Regex.Replace(@"one two three four", @"(?&lt;one&gt;\w+) (\w+) (?&lt;three&gt;\w+) (\w+)", @"$1 $2 $3 $4") // result: "two four one three" </code></pre> <p>In effect, the <em>number</em> is an alias for the <em>name</em>; the numbers assigned to named groups start where the "real" numbered groups leave off. That may seem like a bizarre policy, but there's a good reason for it: in .NET regexes you can use the same group name more than once in a regex. That makes possible regexes like the one from <a href="https://stackoverflow.com/questions/1295327/regex-to-parse-international-floating-point-numbers">this thread</a> for matching floating-point numbers from different locales:</p> <pre><code>^[+-]?[0-9]{1,3} (?: (?:(?&lt;thousand&gt;\,)[0-9]{3})* (?:(?&lt;decimal&gt;\.)[0-9]{2})? | (?:(?&lt;thousand&gt;\.)[0-9]{3})* (?:(?&lt;decimal&gt;\,)[0-9]{2})? | [0-9]* (?:(?&lt;decimal&gt;[\.\,])[0-9]{2})? )$ </code></pre> <p>If there's a thousands separator, it will be saved in group "thousand" no matter which part of the regex matched it. Similarly, the decimal separator (if there is one) will always be saved in group "decimal". Of course, there are ways to identify and extract the separators without reusable named groups, but this way is so much more convenient, I think it more than justifies the weird numbering scheme.</p> <p>And then there's Perl 5.10+, which gives us more control over capturing groups than I know what to do with. :D</p>
    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. 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.
    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