Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Match.Groups Property

Gets a collection of groups matched by the regular expression.

Namespace: DevExpress.XtraRichEdit.API.Native

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

NuGet Package: DevExpress.RichEdit.Core

#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.

View Example

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