.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

SubDocument.FindAll(Regex) Method

Finds all occurrences of a character pattern specified by the regular expression.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v21.1.Core.dll

Declaration

DocumentRange[] FindAll(
    Regex regex
)

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 how to find all six-letter words in a document.

Document document = wordProcessor1.Document;
document.LoadDocument("Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
document.InsertSection(document.Range.Start);

// Specify a regular expression that will find all six letter words.
System.Text.RegularExpressions.Regex expr =
    new System.Text.RegularExpressions.Regex("\\b\\w{6}\\b");
System.Collections.Specialized.StringCollection sixLetterWords =
    new System.Collections.Specialized.StringCollection();

// Perform the search.
DocumentRange[] found = document.FindAll(expr);
foreach (DocumentRange r in found)
{
    sixLetterWords.Add(document.GetText(r));
}
document.BeginUpdate();

// Insert an ordered list of non-repetitive words in the beginning of the document.
var distinctWords = sixLetterWords.Cast<string>().Distinct().OrderByDescending(s => s);
foreach (var s in distinctWords)
{
    document.InsertText(document.Range.Start, s.ToString() + Environment.NewLine);
}
document.EndUpdate();
See Also