Regex.Matches Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Searches an input string for all occurrences of a regular expression and returns all the matches.
Overloads
| Name | Description |
|---|---|
| Matches(String, String, RegexOptions, TimeSpan) |
Searches the specified input string for all occurrences of a specified regular expression, using the specified matching options and time-out interval. |
| Matches(String, String, RegexOptions) |
Searches the specified input string for all occurrences of a specified regular expression, using the specified matching options. |
| Matches(String, Int32) |
Searches the specified input string for all occurrences of a regular expression, beginning at the specified starting position in the string. |
| Matches(String) |
Searches the specified input string for all occurrences of a regular expression. |
| Matches(String, String) |
Searches the specified input string for all occurrences of a specified regular expression. |
Matches(String, String, RegexOptions, TimeSpan)
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
Searches the specified input string for all occurrences of a specified regular expression, using the specified matching options and time-out interval.
public:
static System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input, System::String ^ pattern, System::Text::RegularExpressions::RegexOptions options, TimeSpan matchTimeout);
public static System.Text.RegularExpressions.MatchCollection Matches(string input, string pattern, System.Text.RegularExpressions.RegexOptions options, TimeSpan matchTimeout);
static member Matches : string * string * System.Text.RegularExpressions.RegexOptions * TimeSpan -> System.Text.RegularExpressions.MatchCollection
Public Shared Function Matches (input As String, pattern As String, options As RegexOptions, matchTimeout As TimeSpan) As MatchCollection
Parameters
- input
- String
The string to search for a match.
- pattern
- String
The regular expression pattern to match.
- options
- RegexOptions
A bitwise combination of the enumeration values that specify options for matching.
- matchTimeout
- TimeSpan
A time-out interval, or InfiniteMatchTimeout to indicate that the method should not time out.
Returns
A collection of the Match objects found by the search. If no matches are found, the method returns an empty collection object.
Exceptions
A regular expression parsing error occurred.
input or pattern is null.
options is not a valid bitwise combination of RegexOptions values.
-or-
matchTimeout is negative, zero, or greater than approximately 24 days.
Remarks
The Matches(String, String, RegexOptions, TimeSpan) method is similar to the Match(String, String, RegexOptions, TimeSpan) method, except that it returns information about all the matches found in the input string, instead of a single match.
The static Matches methods are equivalent to constructing a Regex object with the specified regular expression pattern and calling the instance method Matches.
The Matches(String, String, RegexOptions, TimeSpan) method uses lazy evaluation to populate the returned MatchCollection object. Accessing members of this collection such as Count and CopyTo(Array, Int32) causes the collection to be populated immediately. To take advantage of lazy evaluation, iterate the collection by using foreach.
Because of its lazy evaluation, calling the Matches(String, String, RegexOptions, TimeSpan) method does not throw a RegexMatchTimeoutException exception. However, an exception is thrown when an operation is performed on the MatchCollection object returned by this method, if a matching operation exceeds the time-out interval specified by the matchTimeout parameter.
Notes to Callers
We recommend that you set the matchTimeout parameter to an appropriate value, such as two seconds. If you disable time-outs by specifying InfiniteMatchTimeout, the regular expression engine offers slightly better performance. However, you should disable time-outs only under the following conditions:
When the input processed by a regular expression is derived from a known and trusted source or consists of static text. This excludes text that has been dynamically input by users.
When the regular expression pattern has been thoroughly tested to ensure that it efficiently handles matches, non-matches, and near matches.
When the regular expression pattern contains no language elements that are known to cause excessive backtracking when processing a near match.
See also
Applies to
Matches(String, String, RegexOptions)
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
Searches the specified input string for all occurrences of a specified regular expression, using the specified matching options.
public:
static System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input, System::String ^ pattern, System::Text::RegularExpressions::RegexOptions options);
public static System.Text.RegularExpressions.MatchCollection Matches(string input, string pattern, System.Text.RegularExpressions.RegexOptions options);
static member Matches : string * string * System.Text.RegularExpressions.RegexOptions -> System.Text.RegularExpressions.MatchCollection
Public Shared Function Matches (input As String, pattern As String, options As RegexOptions) As MatchCollection
Parameters
- input
- String
The string to search for a match.
- pattern
- String
The regular expression pattern to match.
- options
- RegexOptions
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.
Exceptions
A regular expression parsing error occurred.
input or pattern is null.
options is not a valid bitwise combination of RegexOptions values.
Remarks
The Matches(String, String, RegexOptions) method is similar to the Match(String, String, RegexOptions) method, except that it returns information about all the matches found in the input string, instead of a single match.
The static Matches methods are equivalent to constructing a Regex object with the specified regular expression pattern and calling the instance method Matches.
The Matches(String, String, RegexOptions) method uses lazy evaluation to populate the returned MatchCollection object. Accessing members of this collection such as Count and CopyTo(Array, Int32) causes the collection to be populated immediately. To take advantage of lazy evaluation, iterate the collection by using foreach.
Because of its lazy evaluation, calling the Matches(String, String, RegexOptions) method does not throw a RegexMatchTimeoutException exception. However, the exception is thrown when an operation is performed on the MatchCollection object returned by this method, if a matching operation exceeds the time-out interval.
Notes to Callers
This method times out after an interval that is equal to the default time-out value of the application domain in which it is called. If a time-out value has not been defined for the application domain, the value InfiniteMatchTimeout, which prevents the method from timing out, is used. The recommended static method for retrieving multiple pattern matches is Matches(String, String, RegexOptions, TimeSpan), which lets you set the time-out interval.
See also
Applies to
Matches(String, Int32)
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
Searches the specified input string for all occurrences of a regular expression, beginning at the specified starting position in the string.
public:
System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input, int startat);
public System.Text.RegularExpressions.MatchCollection Matches(string input, int startat);
member this.Matches : string * int -> System.Text.RegularExpressions.MatchCollection
Public Function Matches (input As String, startat As Integer) As MatchCollection
Parameters
- input
- String
The string to search for a match.
- startat
- Int32
The character position in the input string at which to start the search.
Returns
A collection of the Match objects found by the search. If no matches are found, the method returns an empty collection object.
Exceptions
input is null.
startat is less than zero or greater than the length of input.
Remarks
The Matches(String, Int32) method is similar to the Match(String, Int32) method, except that it returns information about all the matches found in the input string, instead of a single match.
For more details about startat, see the remarks for Match(String, Int32).
The Matches(String, Int32) method uses lazy evaluation to populate the returned MatchCollection object. Accessing members of this collection such as Count and CopyTo(Array, Int32) causes the collection to be populated immediately. To take advantage of lazy evaluation, iterate the collection by using foreach.
Because of its lazy evaluation, calling the Matches(String, Int32) method does not throw a RegexMatchTimeoutException exception. However, the exception is thrown when an operation is performed on the MatchCollection object returned by this method, if the MatchTimeout property is not InfiniteMatchTimeout and a matching operation exceeds the time-out interval.
See also
Applies to
Matches(String)
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
Searches the specified input string for all occurrences of a regular expression.
public:
System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input);
public System.Text.RegularExpressions.MatchCollection Matches(string input);
member this.Matches : string -> System.Text.RegularExpressions.MatchCollection
Public Function Matches (input As String) As MatchCollection
Parameters
- input
- String
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.
Exceptions
input is null.
Remarks
The Matches(String) method is similar to the Match(String) method, except that it returns information about all the matches found in the input string, instead of a single match. The collection includes only matches and terminates at the first non-match.
The Matches(String) method uses lazy evaluation to populate the returned MatchCollection object. Accessing members of this collection such as Count and CopyTo(Array, Int32) causes the collection to be populated immediately. To take advantage of lazy evaluation, iterate the collection by using foreach.
Because of its lazy evaluation, calling the Matches(String) method does not throw a RegexMatchTimeoutException exception. However, the exception is thrown when an operation is performed on the MatchCollection object returned by this method, if the MatchTimeout property is not InfiniteMatchTimeout and a matching operation exceeds the time-out interval.
See also
Applies to
Matches(String, String)
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
- Source:
- Regex.Match.cs
Searches the specified input string for all occurrences of a specified regular expression.
public:
static System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input, System::String ^ pattern);
public static System.Text.RegularExpressions.MatchCollection Matches(string input, string pattern);
static member Matches : string * string -> System.Text.RegularExpressions.MatchCollection
Public Shared Function Matches (input As String, pattern As String) As MatchCollection
Parameters
- input
- String
The string to search for a match.
- pattern
- String
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.
Exceptions
A regular expression parsing error occurred.
input or pattern is null.
Remarks
The Matches(String, String) method is similar to the Match(String, String) method, except that it returns information about all the matches found in the input string, instead of a single match.
The static Matches methods are equivalent to constructing a Regex object with the specified regular expression pattern and calling the instance method Matches.
The Matches(String, String) method uses lazy evaluation to populate the returned MatchCollection object. Accessing members of this collection such as Count and CopyTo(Array, Int32) causes the collection to be populated immediately. To take advantage of lazy evaluation, iterate the collection by using foreach.
Because of its lazy evaluation, calling the Matches(String, String) method does not throw a RegexMatchTimeoutException exception. However, the exception is thrown when an operation is performed on the MatchCollection object returned by this method, if a matching operation exceeds the time-out interval.
Notes to Callers
This method times out after an interval that is equal to the default time-out value of the application domain in which it is called. If a time-out value has not been defined for the application domain, the value InfiniteMatchTimeout, which prevents the method from timing out, is used. The recommended static method for retrieving multiple pattern matches is Matches(String, String, RegexOptions, TimeSpan), which lets you specify the time-out interval.