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

SubDocument.ReplaceAll(Regex, String, DocumentRange) Method

Replaces all occurrences of a character pattern defined by a regular expression with a specified replacement string.

Namespace: DevExpress.XtraRichEdit.API.Native

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


int ReplaceAll(
    Regex regex,
    string replaceWith,
    DocumentRange range
Function ReplaceAll(
    regex As Regex,
    replaceWith As String,
    range As DocumentRange
) As Integer


Name Type Description
regex Regex

A Regex object representing the regular expression to match.

replaceWith String

A string to replace with. May contain special symbols that represent the contents of capturing parentheses in the regular expression.

range DocumentRange

A DocumentRange specifying the search and replace scope of the document.


Type Description

An integer, representing the number of replacements made.


All strings in the specified document range that match the specified regular expression are replaced. You can use the contents of capturing parentheses in the replacement text via $1, $2, $3, etc. You can even use the named Capture items - they are denoted by named groupings in the replacement string, as illustrated in the code sample below.


The following code snippet illustrates how the SubDocument.ReplaceAll method with Regular Expressions can be used to convert all US formatted dates (month/day/year) in the document to two European formats: year-month-day and day.month.year.

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using System.Text.RegularExpressions;
Document document = wordProcessor.Document;
document.AppendText("12\\14\\2014" + Environment.NewLine);
string pattern = @"(?<mm>\d{2}).(?<dd>\d{2}).(?<yyyy>\d{4})";
string replacementString = @"${yyyy}-${mm}-${dd} or ${dd}.${mm}.${yyyy}";
System.Text.RegularExpressions.Regex myRegEx =
    new System.Text.RegularExpressions.Regex(pattern);
int count = document.ReplaceAll(myRegEx, replacementString);
System.Windows.Forms.MessageBox.Show(String.Format("We've done {0} replacement(s).", count));
See Also