Skip to main content
.NET Framework 4.5.2+

Match.Groups Property

Gets a collection of groups matched by the regular expression.

Namespace: DevExpress.XtraRichEdit.API.Native

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

Declaration

GroupCollection Groups { get; }

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.

Example

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));
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the Groups property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also