Back to Devexpress

Match Interface

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-d7dca2d9.md

latest2.9 KB
Original Source

Match Interface

Represents the result of a regular expression matching operation.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
[ComVisible(true)]
public interface Match :
    Group,
    Capture
vb
<ComVisible(True)>
Public Interface Match
    Inherits Group,
             Capture

The following members return Match objects:

Remarks

A Match represents text that is matched by a given pattern, when a regular expression search is performed on the document.

If parts of a pattern are enclosed in parentheses, the corresponding results can be accessed via the Match.Groups property.

Example

The following code illustrates how to find and parse dates in US format using Regular Expression pattern matching:

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

Match Members

DevExpress.XtraRichEdit.API.Native Namespace