C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
And: The pattern in the Regex specifies that a match must start with s, have one or more non-whitespace characters, and end in d.
Info: The Regex.Matches function returns a MatchCollection. We use the For-Each looping construct on it (matches).
For Each, ForThen: In a nested loop, we enumerate all the Capture instances. We access the Index and Value from each Capture.
Note: Each capture has an Index (the character position of the capture in the source string) and a Value (the matching substring itself).
VB.NET program that uses Regex.Matches
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
' Input string.
Dim value As String = "said shed see spear spread super"
' Call Regex.Matches method.
Dim matches As MatchCollection = Regex.Matches(value, "s\w+d")
' Loop over matches.
For Each m As Match In matches
' Loop over captures.
For Each c As Capture In m.Captures
' Display.
Console.WriteLine("Index={0}, Value={1}", c.Index, c.Value)
Next
Next
End Sub
End Module
Output
Index=0, Value=said
Index=5, Value=shed
Index=20, Value=spread