Namespace: System.Text.RegularExpressions
Regex
Represents an immutable regular expression.
Properties (1)
RegexOptions Options
Gets the options that were passed into the Regex constructor.
Value: One or more members of the RegexOptions enumeration that represent options that were passed to the Regex constructor
Methods (19)
Regex(String)Constructor
Initializes a new instance of the Regex class for the specified regular expression.
| Parameter | Description |
|---|---|
| pattern | The regular expression pattern to match. |
Regex(String,Text.RegularExpressions.RegexOptions)Constructor
Initializes a new instance of the Regex class for the specified regular expression, with options that modify the pattern.
| Parameter | Description |
|---|---|
| pattern | The regular expression pattern to match. |
| options | A bitwise combination of the enumeration values that modify the regular expression. |
bool IsMatch(String)
Indicates whether the regular expression specified in the Regex constructor finds a match in a specified input string.
| Parameter | Description |
|---|---|
| input | The string to search for a match. |
Returns: true if the regular expression finds a match; otherwise, false.
bool IsMatch(String,String)
Indicates whether the specified regular expression finds a match in the specified input string.
| Parameter | Description |
|---|---|
| input | The string to search for a match. |
| pattern | The regular expression pattern to match. |
Returns: true if the regular expression finds a match; otherwise, false.
bool IsMatch(String,String,Text.RegularExpressions.RegexOptions)
Indicates whether the specified regular expression finds a match in the specified input string, using the specified matching options.
| Parameter | Description |
|---|---|
| input | The string to search for a match. |
| pattern | The regular expression pattern to match. |
| options | A bitwise combination of the enumeration values that provide options for matching. |
Returns: true if the regular expression finds a match; otherwise, false.
Match Match(String)
Searches the specified input string for the first occurrence of the regular expression specified in the Regex constructor.
| Parameter | Description |
|---|---|
| input | The string to search for a match. |
Returns: An object that contains information about the match.
Match Match(String,String)
Searches the specified input string for the first occurrence of the specified regular expression.
| Parameter | Description |
|---|---|
| input | The string to search for a match. |
| pattern | The regular expression pattern to match. |
Returns: An object that contains information about the match.
Match Match(String,String,Text.RegularExpressions.RegexOptions)
Searches the input string for the first occurrence of the specified regular expression, using the specified matching options.
| Parameter | Description |
|---|---|
| input | The string to search for a match. |
| pattern | The regular expression pattern to match. |
| options | A bitwise combination of the enumeration values that provide options for matching. |
Returns: An object that contains information about the match.
MatchCollection Matches(String)
Searches the specified input string for all occurrences of a regular expression.
| Parameter | Description |
|---|---|
| input | The string to search for a match. |
Returns: A collection of the Match objects found by the search. If no matches are found, the method returns an empty collection object.
MatchCollection Matches(String,String)
Searches the specified input string for all occurrences of a specified regular expression.
| Parameter | Description |
|---|---|
| input | The string to search for a match. |
| pattern | The regular expression pattern to match. |
Returns: A collection of the Match objects found by the search. If no matches are found, the method returns an empty collection object.
MatchCollection Matches(String,String,Text.RegularExpressions.RegexOptions)
Searches the specified input string for all occurrences of a specified regular expression, using the specified matching options.
| Parameter | Description |
|---|---|
| input | The string to search for a match. |
| pattern | The regular expression pattern to match. |
| options | A bitwise combination of the enumeration values that specify options for matching. |
Returns: A collection of the Match objects found by the search. If no matches are found, the method returns an empty collection object.
String Replace(String,String)
In a specified input string, replaces all strings that match a regular expression pattern with a specified replacement string.
| Parameter | Description |
|---|---|
| input | The string to search for a match. |
| replacement | The replacement string. |
Returns: A new string that is identical to the input string, except that the replacement string takes the place of each matched string. If the regular expression pattern is not matched in the current instance, the method returns the current instance unchanged.
String Replace(String,String,String)
In a specified input string, replaces all strings that match a specified regular expression with a specified replacement string.
| Parameter | Description |
|---|---|
| input | The string to search for a match. |
| pattern | The regular expression pattern to match. |
| replacement | The replacement string. |
Returns: A new string that is identical to the input string, except that the replacement string takes the place of each matched string. If pattern is not matched in the current instance, the method returns the current instance unchanged.
String Replace(String,String,String,Text.RegularExpressions.RegexOptions)
In a specified input string, replaces all strings that match a specified regular expression with a specified replacement string. Specified options modify the matching operation.
| Parameter | Description |
|---|---|
| input | The string to search for a match. |
| pattern | The regular expression pattern to match. |
| replacement | The replacement string. |
| options | A bitwise combination of the enumeration values that provide options for matching. |
Returns: A new string that is identical to the input string, except that the replacement string takes the place of each matched string. If pattern is not matched in the current instance, the method returns the current instance unchanged.
String[] Split(String)
Splits an input string into an array of substrings at the positions defined by a regular expression pattern specified in the Regex constructor.
| Parameter | Description |
|---|---|
| input | The string to split. |
Returns: An array of strings.
String[] Split(String,String)
Splits an input string into an array of substrings at the positions defined by a regular expression pattern.
| Parameter | Description |
|---|---|
| input | The string to split. |
| pattern | The regular expression pattern to match. |
Returns: An array of strings.
String[] Split(String,String,Text.RegularExpressions.RegexOptions)
Splits an input string into an array of substrings at the positions defined by a specified regular expression pattern. Specified options modify the matching operation.
| Parameter | Description |
|---|---|
| input | The string to split. |
| pattern | The regular expression pattern to match. |
| options | A bitwise combination of the enumeration values that provide options for matching. |
Returns: An array of strings.
String Escape(String)
Escapes a minimal set of characters (\, *, +, ?, |, {, [, (,), ^, $, ., #, and white space) by replacing them with their escape codes. This instructs the regular expression engine to interpret these characters literally rather than as metacharacters.
| Parameter | Description |
|---|---|
| str | The input string that contains the text to convert. |
Returns: A string of characters with metacharacters converted to their escaped form.
String ToString
Returns the regular expression pattern that was passed into the Regex constructor.
Returns: The pattern parameter that was passed into the Regex constructor.