Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to retrieve a specific group name you can use the <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx" rel="noreferrer"><code>Regex</code></a><code>.</code><a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.groupnamefromnumber.aspx" rel="noreferrer"><code>GroupNameFromNumber</code></a> method.</p> <pre><code>//regular expression with a named group Regex regex = new Regex(@"(?&lt;Type1&gt;AAA)|(?&lt;Type2&gt;BBB)", RegexOptions.Compiled); //evaluate results of Regex and for each match foreach (Match m in regex.Matches("AAABBBAAA")) { //loop through all the groups in current match for(int x = 1; x &lt; m.Groups.Count; x ++) { //print the names wherever there is a succesful match if(m.Group[x].Success) Console.WriteLine(regex.GroupNameFromNumber(x)); } } </code></pre> <p>Also, There is a string indexer on the <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.groupcollection.aspx" rel="noreferrer"><code>GroupCollection</code></a>. object that is accesible on the <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.match.aspx" rel="noreferrer"><code>Match</code></a><code>.</code><a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.match.groups.aspx" rel="noreferrer"><code>Groups</code></a> property, this allows you to access a group in a match by name instead of by index.</p> <pre><code>//regular expression with a named group Regex regex = new Regex(@"(?&lt;Type1&gt;AAA)|(?&lt;Type2&gt;BBB)", RegexOptions.Compiled); //evaluate results of Regex and for each match foreach (Match m in regex.Matches("AAABBBAAA")) { //print the value of the named group if(m.Groups["Type1"].Success) Console.WriteLine(m.Groups["Type1"].Value); if(m.Groups["Type2"].Success) Console.WriteLine(m.Groups["Type2"].Value); } </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. 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