SubDocument.FindAll(Regex) Method
Finds all occurrences of a character pattern specified by the regular expression.
Namespace: DevExpress.XtraRichEdit.API.Native
Assembly: DevExpress.RichEdit.v19.1.Core.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
regex | Regex | A Regex object representing a regular expression to search. |
Returns
Type | Description |
---|---|
DocumentRange[] | An array of DocumentRange objects representing ranges in the document matching the specified pattern. |
Remarks
The default maximum length of a string that can be obtained in a regular expression search is 128 characters. Use the DocumentSearchOptions.RegExResultMaxGuaranteedLength property to change the maximum string length.
Example
This code snippet illustrates the use of the Regular Expression feature to find all six-letter words in a document.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/winforms-richedit-document-api-e5219
document.LoadDocument("Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
document.InsertSection(document.Range.Start)
' Specify a regular expression that will find all six letter words.
Dim expr As New System.Text.RegularExpressions.Regex("\b\w{6}\b")
Dim sixLetterWords As New System.Collections.Specialized.StringCollection()
' Perform the search.
Dim found() As DocumentRange = document.FindAll(expr)
For Each r As DocumentRange In found
sixLetterWords.Add(document.GetText(r))
Next r
document.BeginUpdate()
' Insert an ordered list of non-repetitive words in the beginning of the document.
Dim distinctWords = sixLetterWords.Cast(Of String)().Distinct().OrderByDescending(Function(s) s)
For Each s In distinctWords
document.InsertText(document.Range.Start, s.ToString() & Environment.NewLine)
Next s
document.EndUpdate()
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the FindAll(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.