Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

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.v19.1.Core.dll

Declaration

int ReplaceAll(
    Regex regex,
    string replaceWith,
    DocumentRange range
)

Parameters

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.

Returns

Type Description
Int32

An integer, representing the number of replacements made.

Remarks

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.

Example

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.

document.AppendText("12\14\2014" & Environment.NewLine)
Dim pattern As String = "(?<mm>\d{2}).(?<dd>\d{2}).(?<yyyy>\d{4})"
Dim replacementString As String = "${yyyy}-${mm}-${dd} or ${dd}.${mm}.${yyyy}"
Dim myRegEx As New System.Text.RegularExpressions.Regex(pattern)
Dim count As Integer = document.ReplaceAll(myRegEx, replacementString)
System.Windows.Forms.MessageBox.Show(String.Format("We've done {0} replacement(s).", count))
See Also