In This Article

ReplacementRegexCode Class

Implements regular expression engine code that can execute replacement logic.

public class ReplacementRegexCode : RegexCodeBase
Inheritance:
object RegexCodeBase object

Properties

RequiresCaptures

Indicates whether applying this replacement requires regular expression captures.

public bool RequiresCaptures { get; }

Property Value

bool

Methods

ApplySubstitutions(IEnumerable<RegexCapture>, int)

Attempts to apply substitutions from another regular expression match's capture results.

public string ApplySubstitutions(IEnumerable<RegexCapture> captures, int definedCaptureCount)
Parameter Type Description
captures IEnumerable<RegexCapture>

The capture results from another regular expression match.

definedCaptureCount int

The number of capture groups defined by the match pattern, including the implicit full-match capture at index 0.

Returns

string:

The result of the replacement.

Remarks

The definedCaptureCount value is pattern metadata and is not the same as the number of returned captures. Missing capture references outside the defined capture range are preserved as literal replacement text.

Create(string)

Creates a ReplacementRegexCode instance.

public static ReplacementRegexCode Create(string pattern)
Parameter Type Description
pattern string

A text regular expression pattern.

Returns

ReplacementRegexCode

EscapePattern(string?)

Escapes all special characters in the specified pattern.

public static string? EscapePattern(string? pattern)
Parameter Type Description
pattern string

The pattern to escape.

Returns

string:

The escaped pattern.

Inherited Members

Extension Methods