Skip to content

Regex.Replace Method

Definition

Namespace: Corvus.Ecma262.RegularExpressions
Assembly: Corvus.Regex.Ecma262.dll

Overloads

Method Description
Replace(string, string, string, RegexFlags) Replaces the matches of a pattern in a text (every match with Global, the first otherwise).
Replace(string, string) Replaces the matches in a text: every match with Global, the first otherwise, as String.prototype.replace does. The replacement...
Replace(string, MatchEvaluator) Replaces the matches in a text (every match with Global, the first otherwise) with what an evaluator gives for each, used as it is.
Replace(ReadOnlySpan<char>, ReadOnlySpan<char>, IBufferWriter<char>) Replaces the matches in a UTF-16 text and writes the result to a buffer writer, allocating nothing itself (see TryReplace).
Replace(ReadOnlySpan<byte>, ReadOnlySpan<byte>, IBufferWriter<byte>) Replaces the matches in a UTF-8 text and writes the result to a buffer writer, allocating nothing itself.
Replace(ReadOnlySpan<char>, SpanMatchEvaluator, IBufferWriter<char>) Replaces the matches in a UTF-16 text (every match with Global, the first otherwise) with what an evaluator writes for each, and w...
Replace(ReadOnlySpan<byte>, Utf8MatchEvaluator, IBufferWriter<byte>) Replaces the matches in a UTF-8 text with what an evaluator writes for each, and writes the result to a buffer writer, allocating nothing itself.

Replace(string, string, string, RegexFlags)

Source: Regex.Matching.cs

Replaces the matches of a pattern in a text (every match with Global, the first otherwise).

public static string Replace(string input, string pattern, string replacement, RegexFlags flags)

Parameters

Name Type Description
input string The text.
pattern string The pattern.
replacement string The replacement (see Result).
flags RegexFlags The flags. (optional)

Returns

string

The text with the replacements made.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Replace(string, string)

Source: Regex.Matching.cs

Replaces the matches in a text: every match with Global, the first otherwise, as String.prototype.replace does. The replacement is expanded as Result expands it.

public string Replace(string input, string replacement)

Parameters

Name Type Description
input string The text.
replacement string The replacement.

Returns

string

The text with the replacements made.

Exceptions

Exception Description
RegexMatchTimeoutException A match reached its limit.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Replace(string, MatchEvaluator)

Source: Regex.Matching.cs

Replaces the matches in a text (every match with Global, the first otherwise) with what an evaluator gives for each, used as it is.

public string Replace(string input, MatchEvaluator evaluator)

Parameters

Name Type Description
input string The text.
evaluator MatchEvaluator The evaluator.

Returns

string

The text with the replacements made.

Exceptions

Exception Description
RegexMatchTimeoutException A match reached its limit.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Replace(ReadOnlySpan<char>, ReadOnlySpan<char>, IBufferWriter<char>)

Source: Regex.Spans.cs

Replaces the matches in a UTF-16 text and writes the result to a buffer writer, allocating nothing itself (see TryReplace).

public void Replace(ReadOnlySpan<char> input, ReadOnlySpan<char> replacement, IBufferWriter<char> destination)

Parameters

Name Type Description
input ReadOnlySpan<char> The text.
replacement ReadOnlySpan<char> The replacement.
destination IBufferWriter<char> Where to write the result.

Exceptions

Exception Description
RegexMatchTimeoutException A match reached its limit.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Replace(ReadOnlySpan<byte>, ReadOnlySpan<byte>, IBufferWriter<byte>)

Source: Regex.Spans.cs

Replaces the matches in a UTF-8 text and writes the result to a buffer writer, allocating nothing itself.

public void Replace(ReadOnlySpan<byte> utf8, ReadOnlySpan<byte> replacement, IBufferWriter<byte> destination)

Parameters

Name Type Description
utf8 ReadOnlySpan<byte> The text.
replacement ReadOnlySpan<byte> The replacement, as UTF-8.
destination IBufferWriter<byte> Where to write the result.

Exceptions

Exception Description
RegexMatchTimeoutException A match reached its limit.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Replace(ReadOnlySpan<char>, SpanMatchEvaluator, IBufferWriter<char>)

Source: Regex.Spans.cs

Replaces the matches in a UTF-16 text (every match with Global, the first otherwise) with what an evaluator writes for each, and writes the result to a buffer writer, allocating nothing itself.

public void Replace(ReadOnlySpan<char> input, SpanMatchEvaluator evaluator, IBufferWriter<char> destination)

Parameters

Name Type Description
input ReadOnlySpan<char> The text.
evaluator SpanMatchEvaluator The evaluator.
destination IBufferWriter<char> Where to write the result.

Exceptions

Exception Description
RegexMatchTimeoutException A match reached its limit.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Replace(ReadOnlySpan<byte>, Utf8MatchEvaluator, IBufferWriter<byte>)

Source: Regex.Spans.cs

Replaces the matches in a UTF-8 text with what an evaluator writes for each, and writes the result to a buffer writer, allocating nothing itself.

public void Replace(ReadOnlySpan<byte> utf8, Utf8MatchEvaluator evaluator, IBufferWriter<byte> destination)

Parameters

Name Type Description
utf8 ReadOnlySpan<byte> The text.
evaluator Utf8MatchEvaluator The evaluator.
destination IBufferWriter<byte> Where to write the result.

Exceptions

Exception Description
RegexMatchTimeoutException A match reached its limit.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Collaborate with us on GitHub

The source for this content can be found on GitHub, where you can also create and review issues and pull requests.

Open an issue