How Do I...Get all matches for a pattern
Regular Expressions are often useful when trying to retrieve small portions of
text from a large document, result set, or when filtering a stream. The MatchCollection
object contains all valid Match objects for a given regular expression after a
successful match occurs.
Dim DigitRegex As Regex = New Regex("(?<number>\d+)")
Dim S As String = "abc 123 def 456 ghi 789"
...
Dim Mc As MatchCollection = DigitRegex.Matches(S)
VB
The following example illustrates how to create a Regex that matches numbers in a string.
The Matches method is callled to return a MatchCollection. If the Count
property equals 0, no successful matches have occured. If there are matches, the results
of each are displayed.
Example
VB RegexMatches.exe
Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.
|