Skip to main content
A newer version of this page is available. .
.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.v19.1.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)
Dim result As IRegexSearchResult
Dim pattern As String = "(?<mm>\d{2}).(?<dd>\d{2}).(?<yyyy>\d{4})"
Dim myRegEx As New System.Text.RegularExpressions.Regex(pattern)

result = document.StartSearch(myRegEx)
If result.FindNext() Then
    Dim dayFound As String = result.Match.Groups(2).Value
    Dim monthFound As String = result.Match.Groups(1).Value
    Dim yearFound As String = 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))
End If
See Also