.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Match.Groups Property

Gets a collection of groups matched by the regular expression.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v20.2.Core.dll

Declaration

GroupCollection Groups { get; }
ReadOnly Property Groups As GroupCollection

Property Value

Type Description
GroupCollection

A GroupCollection object representing character groups matched by the pattern.

Remarks

Part of a regular expression pattern can be placed inside round brackets or parentheses, forming a group.

For example, the regular expression pattern (?<mm>\d{2}).(?<dd>\d{2}).(?<yyyy>\d{4}), that matches US formatted date (e.g. 12/25/2011 for a future Christmas), has three named groups. The first group named 'mm' consists of the month number. This group is captured by the first portion of the regular expression, (?<mm>\d{2}). Subsequent groups contain a day number and a year. The original match ('12/25/2011') is located in the first element of the group collection with the index 0.

All groups can then be retrieved from the GroupCollection object that is returned by the Groups property, as the following example shows.

Examples

This code snippet uses Regular Expressions to find a date in US format within the document text and parse it.

document.AppendText("12\\14\\2014" + Environment.NewLine);
IRegexSearchResult result;
string pattern = @"(?<mm>\d{2}).(?<dd>\d{2}).(?<yyyy>\d{4})";
System.Text.RegularExpressions.Regex myRegEx = 
    new System.Text.RegularExpressions.Regex(pattern);

result = document.StartSearch(myRegEx);
if (result.FindNext())
{
    string dayFound = result.Match.Groups[2].Value;
    string monthFound = result.Match.Groups[1].Value;
    string yearFound = result.Match.Groups[3].Value;
    document.AppendText(String.Format("Found a date that is the {0} day of the {1} month of the {2} year.",
        dayFound, monthFound, yearFound));
}
See Also