Class RegexExtensions
- Namespace
- NuvTools.Common.RegularExpressions
- Assembly
- NuvTools.Common.dll
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
valuestringpatternstringThe regular expression pattern to match.
optionsRegexOptionsOptional RegexOptions to modify the search behavior. Default is IgnoreCase.
Returns
Exceptions
- ArgumentException
Thrown if
patternis 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
valuestringThe input string to search. If null, returns an empty Match(string?, string, RegexOptions).
patternstringThe regular expression pattern to match.
optionsRegexOptionsOptional 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. Ifvalueis null, returns an empty match.
Exceptions
- ArgumentException
Thrown if
patternis 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
valuestringThe input string to modify. If null, returns an empty string.
patternstringThe regular expression pattern to match.
newValuestringThe replacement string. If null, it is treated as an empty string.
optionsRegexOptionsOptional 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
patternhave been replaced withnewValue.
Exceptions
- ArgumentException
Thrown if
patternis null or empty.