Back to Devexpress

SubDocument.StartSearch(Regex) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-subdocument-dot-startsearch-x28-system-dot-text-dot-regularexpressions-dot-regex-x29.md

latest5.2 KB
Original Source

SubDocument.StartSearch(Regex) Method

Provides a search interface for a search in the document, using a regular expression pattern.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
IRegexSearchResult StartSearch(
    Regex regex
)
vb
Function StartSearch(
    regex As Regex
) As IRegexSearchResult

Parameters

NameTypeDescription
regexRegex

A Regex object representing a search pattern.

|

Returns

TypeDescription
IRegexSearchResult

An IRegexSearchResult interface used to perform a search.

|

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

The following code snippets (auto-collected from DevExpress Examples) contain references to the StartSearch(Regex) method.

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.

winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/SearchAndReplace.cs#L45

csharp
result = document.StartSearch(myRegEx);
if (result.FindNext())

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/SearchAndReplaceActions.cs#L45

csharp
result = document.StartSearch(myRegEx);
if (result.FindNext())

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/SearchAndReplace.vb#L39

vb
Dim myRegEx As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex(pattern)
result = document.StartSearch(myRegEx)
If result.FindNext() Then

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/SearchAndReplaceActions.vb#L36

vb
result = document.StartSearch(myRegEx)
If result.FindNext() Then

See Also

SubDocument Interface

SubDocument Members

DevExpress.XtraRichEdit.API.Native Namespace