Regex.Matches Method (String, Int32)
Searches the specified input string for all occurrences of a regular expression, beginning at the specified starting position in the string.
Assembly: System (in System.dll)
The string to search for a match.
The character position in the input string at which to start the search.
The Match(String, Int32) method, except that it returns information about all the matches found in the input string, instead of a single match. It is equivalent to the following code:method is similar to the
The regular expression pattern for which the Regex class constructors. For more information about the elements that can form a regular expression pattern, see Regular Expression Language - Quick Reference.method searches is defined by the call to one of the
The MatchCollection object. Accessing members of this collection such as MatchCollection.Count and MatchCollection.CopyTo causes the collection to be populated immediately. To take advantage of lazy evaluation, you should iterate the collection by using a construct such as foreach in C# and ForEach…Next in Visual Basic.method uses lazy evaluation to populate the returned
Because of its lazy evaluation, calling the 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 Regex.InfiniteMatchTimeout and a matching operation exceeds the time-out interval..method does not throw a
The following example uses the Match(String) method to find the first word in a sentence that ends in "es", and then calls the method to identify any additional words that end in "es".
The regular expression pattern \b\w+es\b is defined as shown in the following table.
Begin the match at a word boundary.
Match one or more word characters.
Match the literal string "es".
End the match at a word boundary.
Available since 8
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1