Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| ' Visual Basic .NET Document | |
| Option Strict On | |
| ' <Snippet12> | |
| Imports System.Text.RegularExpressions | |
| Module Example | |
| Public Sub Main() | |
| Dim pattern As String = "\D+(?<digit>\d+)\D+(?<digit>\d+)?" | |
| Dim inputs() As String = { "abc123def456", "abc123def" } | |
| For Each input As String In inputs | |
| Dim m As Match = Regex.Match(input, pattern) | |
| If m.Success Then | |
| Console.WriteLine("Match: {0}", m.Value) | |
| For grpCtr As Integer = 1 to m.Groups.Count - 1 | |
| Dim grp As Group = m.Groups(grpCtr) | |
| Console.WriteLine("Group {0}: {1}", grpCtr, grp.Value) | |
| For capCtr As Integer = 0 To grp.Captures.Count - 1 | |
| Console.WriteLine(" Capture {0}: {1}", capCtr, | |
| grp.Captures(capCtr).Value) | |
| Next | |
| Next | |
| Else | |
| Console.WriteLine("The match failed.") | |
| End If | |
| Console.WriteLine() | |
| Next | |
| End Sub | |
| End Module | |
| ' The example displays the following output: | |
| ' Match: abc123def456 | |
| ' Group 1: 456 | |
| ' Capture 0: 123 | |
| ' Capture 1: 456 | |
| ' | |
| ' Match: abc123def | |
| ' Group 1: 123 | |
| ' Capture 0: 123 | |
| ' </Snippet12> | |