RegexExtensions Class

Provides extension methods for Regex.

public static class RegexExtensions

Methods

NameDescription
ReplaceAsync(Regex, string, Func<Match, CancellationToken, ValueTask<string>>, int, int, CancellationToken)Replaces at most count matches, searched from startat, in the input string using an asynchronous replacement function.
ReplaceAsync(Regex, string, Func<Match, CancellationToken, ValueTask<string>>, int, CancellationToken)Replaces at most count matches in the input string using an asynchronous replacement function.
ReplaceAsync(Regex, string, Func<Match, CancellationToken, ValueTask<string>>, CancellationToken)Replaces all matches in the input string using an asynchronous replacement function.
ReplaceAsync(Regex, string, Func<Match, Task<string>>)Replaces all matches in the input string using an asynchronous replacement function.
ReplaceAsync(Regex, string, Func<Match, Task<string>>, int, int, CancellationToken)Replaces at most count matches, searched from startat, in the input string using an asynchronous replacement function.
ReplaceAsync(Regex, string, Func<Match, Task<string>>, int, CancellationToken)Replaces at most count matches in the input string using an asynchronous replacement function.
ReplaceAsync(Regex, string, Func<Match, Task<string>>, CancellationToken)Replaces all matches in the input string using an asynchronous replacement function.

ReplaceAsync overloads

ReplaceAsync(Regex, string, Func<Match, CancellationToken, ValueTask<string>>, int, int, CancellationToken)

RegexExtensions.cs

Replaces at most count matches, searched from startat, in the input string using an asynchronous replacement function.

public static ValueTask<string> ReplaceAsync(this Regex regex, string input, Func<Match, CancellationToken, ValueTask<string>> replacementFn, int count, int startat, CancellationToken cancellationToken = default)
Parameters
regex Regex
The regular expression.
input string
The string to search for a match.
replacementFn Func<Match, CancellationToken, ValueTask<string>>
The function that computes the replacement of each match. It receives cancellationToken.
count int
The maximum number of times the replacement can occur, or -1 to replace all the matches.
startat int
The character position in the input string where the search begins, as for Regex.Replace.
cancellationToken CancellationToken
The token to monitor for cancellation requests.
Returns

ValueTask<string>

Remarks

The replacement function is called for each match, in the order the matches are found: from right to left when the regex uses RegexOptions.RightToLeft.

ReplaceAsync(Regex, string, Func<Match, CancellationToken, ValueTask<string>>, int, CancellationToken)

RegexExtensions.cs

Replaces at most count matches in the input string using an asynchronous replacement function.

public static ValueTask<string> ReplaceAsync(this Regex regex, string input, Func<Match, CancellationToken, ValueTask<string>> replacementFn, int count, CancellationToken cancellationToken = default)
Parameters
regex Regex
The regular expression.
input string
The string to search for a match.
replacementFn Func<Match, CancellationToken, ValueTask<string>>
The function that computes the replacement of each match. It receives cancellationToken.
count int
The maximum number of times the replacement can occur, or -1 to replace all the matches.
cancellationToken CancellationToken
The token to monitor for cancellation requests.
Returns

ValueTask<string>

Remarks

The replacement function is called for each match, in the order the matches are found: from right to left when the regex uses RegexOptions.RightToLeft.

ReplaceAsync(Regex, string, Func<Match, CancellationToken, ValueTask<string>>, CancellationToken)

RegexExtensions.cs

Replaces all matches in the input string using an asynchronous replacement function.

public static ValueTask<string> ReplaceAsync(this Regex regex, string input, Func<Match, CancellationToken, ValueTask<string>> replacementFn, CancellationToken cancellationToken = default)
Parameters
regex Regex
The regular expression.
input string
The string to search for a match.
replacementFn Func<Match, CancellationToken, ValueTask<string>>
The function that computes the replacement of each match. It receives cancellationToken.
cancellationToken CancellationToken
The token to monitor for cancellation requests.
Returns

ValueTask<string>

Remarks

The replacement function is called for each match, in the order the matches are found: from right to left when the regex uses RegexOptions.RightToLeft.

ReplaceAsync(Regex, string, Func<Match, Task<string>>)

RegexExtensions.cs

Replaces all matches in the input string using an asynchronous replacement function.

public static Task<string> ReplaceAsync(this Regex regex, string input, Func<Match, Task<string>> replacementFn)
Parameters
regex Regex
input string
replacementFn Func<Match, Task<string>>
Returns

Task<string>

Remarks

The replacement function is called for each match, in the order the matches are found: from right to left when the regex uses RegexOptions.RightToLeft.

ReplaceAsync(Regex, string, Func<Match, Task<string>>, int, int, CancellationToken)

RegexExtensions.cs

Replaces at most count matches, searched from startat, in the input string using an asynchronous replacement function.

public static Task<string> ReplaceAsync(this Regex regex, string input, Func<Match, Task<string>> replacementFn, int count, int startat, CancellationToken cancellationToken = default)
Parameters
regex Regex
The regular expression.
input string
The string to search for a match.
replacementFn Func<Match, Task<string>>
The function that computes the replacement of each match.
count int
The maximum number of times the replacement can occur, or -1 to replace all the matches.
startat int
The character position in the input string where the search begins, as for Regex.Replace.
cancellationToken CancellationToken
The token to monitor for cancellation requests.
Returns

Task<string>

Remarks

The replacement function is called for each match, in the order the matches are found: from right to left when the regex uses RegexOptions.RightToLeft.

ReplaceAsync(Regex, string, Func<Match, Task<string>>, int, CancellationToken)

RegexExtensions.cs

Replaces at most count matches in the input string using an asynchronous replacement function.

public static Task<string> ReplaceAsync(this Regex regex, string input, Func<Match, Task<string>> replacementFn, int count, CancellationToken cancellationToken = default)
Parameters
regex Regex
The regular expression.
input string
The string to search for a match.
replacementFn Func<Match, Task<string>>
The function that computes the replacement of each match.
count int
The maximum number of times the replacement can occur, or -1 to replace all the matches.
cancellationToken CancellationToken
The token to monitor for cancellation requests.
Returns

Task<string>

Remarks

The replacement function is called for each match, in the order the matches are found: from right to left when the regex uses RegexOptions.RightToLeft.

ReplaceAsync(Regex, string, Func<Match, Task<string>>, CancellationToken)

RegexExtensions.cs

Replaces all matches in the input string using an asynchronous replacement function.

public static Task<string> ReplaceAsync(this Regex regex, string input, Func<Match, Task<string>> replacementFn, CancellationToken cancellationToken)
Parameters
regex Regex
input string
replacementFn Func<Match, Task<string>>
cancellationToken CancellationToken
Returns

Task<string>

Remarks

The replacement function is called for each match, in the order the matches are found: from right to left when the regex uses RegexOptions.RightToLeft.