These tutorials demonstrate selected features in ASP.NET version 2.0, but they are compatible with later versions of ASP.NET as well. For the current documentation, see the ASP.NET portal on the MSDN Web site.

 

 

   Welcome   |   ASP.NET   |   Web Services   |   Class Browser   
  |   I want my samples in...      

How Do I...? Common Tasks QuickStart Tutorial

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
View Source



Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.