Permalink
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (32 sloc) 1.15 KB
' Visual Basic .NET Document
Option Strict On
' <Snippet1>
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim greedyPattern As String = ".+(\d+)\."
Dim lazyPattern As String = ".+?(\d+)\."
Dim input As String = "This sentence ends with the number 107325."
Dim match As Match
' Match using greedy quantifier .+.
match = Regex.Match(input, greedyPattern)
If match.Success Then
Console.WriteLine("Number at end of sentence (greedy): {0}",
match.Groups(1).Value)
Else
Console.WriteLine("{0} finds no match.", greedyPattern)
End If
' Match using lazy quantifier .+?.
match = Regex.Match(input, lazyPattern)
If match.Success Then
Console.WriteLine("Number at end of sentence (lazy): {0}",
match.Groups(1).Value)
Else
Console.WriteLine("{0} finds no match.", lazyPattern)
End If
End Sub
End Module
' The example displays the following output:
' Number at end of sentence (greedy): 5
' Number at end of sentence (lazy): 107325
' </Snippet1>