NextMatch Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Returns a new Match object with the results for the next match, starting at the position at which the last match ended (at the character after the last matched character).

Namespace:  System.Text.RegularExpressions
Assembly:  System.Text.RegularExpressions (in System.Text.RegularExpressions.dll)

Public Function NextMatch As Match

Return Value

Type: System.Text.RegularExpressions..::..Match
The next regular expression match.

This method is similar to calling Regex..::..Match(String, Int32) again and passing (Index+Length) as the new starting position.


This method does not modify the current instance. Instead, it returns a new Match object that contains information about the next match.

Attempting to retrieve the next match may throw a RegexMatchTimeoutException if a time-out value for matching operations is in effect and the attempt to find the next match exceeds that time-out interval.

Notes to Callers

When a match attempt is repeated by calling the NextMatch method, the regular expression engine gives empty matches special treatment. Usually, NextMatch begins the search for the next match exactly where the previous match left off. However, after an empty match, the NextMatch method advances by one character before trying the next match. This behavior guarantees that the regular expression engine will progress through the string. Otherwise, because an empty match does not result in any forward movement, the next match would start in exactly the same place as the previous match, and it would match the same empty string repeatedly.