Match.NextMatch Method

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

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

'Declaration
Public Function NextMatch As Match
'Usage
Dim instance As Match
Dim returnValue As Match

returnValue = instance.NextMatch
public Match NextMatch ()
public function NextMatch () : Match

Return Value

The next regular expression Match object.

This function is similar to calling Match again and passing (Index+Length) as the new starting position, but it differs from calling Match directly because it handles zero-length match cases in a way that guarantees progress to the end of the string.

Dim text As String = "One car red car blue car"
Dim pat As String = "(\w+)\s+(car)"
' Compile the regular expression.
Dim r As Regex = new Regex(pat, RegexOptions.IgnoreCase)
' Match the regular expression pattern against a text string.
Dim m As Match = r.Match(text)
Dim matchcount as Integer = 0
While (m.Success)
   matchCount += 1
   Console.WriteLine("Match" & (matchCount))
   Dim i As Integer
   For i = 1 to 2
      Dim g as Group = m.Groups(i)
      Console.WriteLine("Group" & i & "='" & g.ToString() & "'")
      Dim cc As CaptureCollection = g.Captures
      Dim j As Integer 
      For j = 0 to cc.Count - 1
	 Dim c As Capture = cc(j)
         Console.WriteLine("Capture" & j & "='" & c.ToString() _
            & "', Position=" & c.Index)
      Next j
   Next i
   m = m.NextMatch()
End While

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show: