Table of Contents

Class RegexExtensions

Namespace
NuvTools.Common.RegularExpressions
Assembly
NuvTools.Common.dll

Provides extension methods for simplifying common Regex operations on string values.

public static class RegexExtensions
Inheritance
RegexExtensions
Inherited Members

Methods

IsMatch(string?, string, RegexOptions)

Determines whether the specified regular expression finds a match in the input string.

public static bool IsMatch(this string? value, string pattern, RegexOptions options = RegexOptions.IgnoreCase)

Parameters

value string

The input string to search. If null, returns false.

pattern string

The regular expression pattern to match.

options RegexOptions

Optional RegexOptions to modify the search behavior. Default is IgnoreCase.

Returns

bool

true if the regular expression finds a match; otherwise, false.

Exceptions

ArgumentException

Thrown if pattern is null or empty.

Match(string?, string, RegexOptions)

Searches the specified input string for the first occurrence of a regular expression pattern.

public static Match Match(this string? value, string pattern, RegexOptions options = RegexOptions.None)

Parameters

value string

The input string to search. If null, returns an empty Match(string?, string, RegexOptions).

pattern string

The regular expression pattern to match.

options RegexOptions

Optional RegexOptions to modify the search behavior. Default is None.

Returns

Match

A Match(string?, string, RegexOptions) object containing information about the first match found in value. If value is null, returns an empty match.

Exceptions

ArgumentException

Thrown if pattern is null or empty.

ReplacePattern(string?, string, string, RegexOptions)

Replaces all occurrences of a specified regular expression pattern in the input string with a replacement string.

public static string? ReplacePattern(this string? value, string pattern, string newValue, RegexOptions options = RegexOptions.None)

Parameters

value string

The input string to modify. If null, returns an empty string.

pattern string

The regular expression pattern to match.

newValue string

The replacement string. If null, it is treated as an empty string.

options RegexOptions

Optional RegexOptions to modify the search behavior. Default is None.

Returns

string

A new string that is identical to the input string except that all instances of pattern have been replaced with newValue.

Exceptions

ArgumentException

Thrown if pattern is null or empty.