Skip to content

Regex.TryReplace Method

Definition

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

Overloads

Method Description
TryReplace(ReadOnlySpan<char>, ReadOnlySpan<char>, Span<char>, int) Replaces the matches in a UTF-16 text (every match with Global, the first otherwise) and writes the result to a span, allocating n...
TryReplace(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>, int) Replaces the matches in a UTF-8 text and writes the result to a span, allocating nothing (see TryReplace).

TryReplace(ReadOnlySpan<char>, ReadOnlySpan<char>, Span<char>, int)

Source: Regex.Spans.cs

Replaces the matches in a UTF-16 text (every match with Global, the first otherwise) and writes the result to a span, allocating nothing. The replacement is expanded as Result expands it.

public bool TryReplace(ReadOnlySpan<char> input, ReadOnlySpan<char> replacement, Span<char> destination, out int written)

Parameters

Name Type Description
input ReadOnlySpan<char> The text.
replacement ReadOnlySpan<char> The replacement.
destination Span<char> Where to write the result.
written int The length of the result, when it fits.

Returns

bool

false when the result does not fit, in which case what was written is not meaningful.

Exceptions

Exception Description
RegexMatchTimeoutException A match reached its limit.

Applies To

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

TryReplace(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>, int)

Source: Regex.Spans.cs

Replaces the matches in a UTF-8 text and writes the result to a span, allocating nothing (see TryReplace).

public bool TryReplace(ReadOnlySpan<byte> utf8, ReadOnlySpan<byte> replacement, Span<byte> destination, out int written)

Parameters

Name Type Description
utf8 ReadOnlySpan<byte> The text.
replacement ReadOnlySpan<byte> The replacement, as UTF-8.
destination Span<byte> Where to write the result.
written int The length of the result, when it fits.

Returns

bool

false when the result does not fit.

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