Class RegexTools
Regular expression tools
Inheritance
Namespace
Syntax
public static class RegexTools
Methods
Filter(string, string)
Filters the string from the substrings matched by the given pattern
Returns
Filtered text
Declaration
public static string Filter(string text, string pattern)
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to be processed |
| pattern | string | Regular expression pattern for replacing |
Filter(string, string, string)
Filters the string from the substrings matched by the given pattern
Returns
Filtered text
Declaration
public static string Filter(string text, string pattern, string replaceWith)
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to be processed |
| pattern | string | Regular expression pattern for replacing |
| replaceWith | string | Replaces the matched substrings with the specified text |
IsMatch(string, string)
Checks to see whether the pattern matches
Returns
True if there are matches. Otherwise, false
Declaration
public static bool IsMatch(string text, string pattern)
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to be matched |
| pattern | string | Regular expression pattern for matching |
IsValidRegex(string)
Determines whether the specified regular expression pattern is valid or not
Returns
True if valid; false otherwise
Declaration
public static bool IsValidRegex(string pattern)
Parameters
| Name | Type | Description |
|---|---|---|
| pattern | string | Specified pattern |
IsValidRegex(Regex)
Determines whether the specified regular expression pattern is valid or not
Returns
True if valid; false otherwise
Declaration
public static bool IsValidRegex(Regex pattern)
Parameters
| Name | Type | Description |
|---|---|---|
| pattern | Regex | Specified pattern |
Match(string, string)
Matches the pattern with the text given
Returns
A System.Text.RegularExpressions.Match that contains information about the current match
Declaration
public static Match Match(string text, string pattern)
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to be matched |
| pattern | string | Regular expression pattern for matching |
Matches(string, string)
Matches the pattern with the text given
Returns
Collection of System.Text.RegularExpressions.Matches that contains information about the current match
Declaration
public static MatchCollection Matches(string text, string pattern)
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to be matched |
| pattern | string | Regular expression pattern for matching |
ParseRegex(string)
Parses the regular expression pattern after validating it
Returns
Regular expression instance of a valid regular expression pattern
Declaration
public static Regex ParseRegex(string pattern)
Parameters
| Name | Type | Description |
|---|---|---|
| pattern | string | Specified pattern |
Split(string, string)
Splits the string using the matched substrings as the delimiters
Returns
Array of strings
Declaration
public static string[] Split(string text, string pattern)
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to be split |
| pattern | string | Regular expression pattern for splitting |
TryParseRegex(string, out Regex?)
Parses the regular expression pattern after validating it
Returns
True if valid; false otherwise
Declaration
public static bool TryParseRegex(string pattern, out Regex? result)
Parameters
| Name | Type | Description |
|---|---|---|
| pattern | string | Specified pattern |
| result | Regex | [out] Resultant regular expression instance |