I have the following VB code snippet which tried to extract the date. But it returns only 7/30/20 instead of 7/30/2002. I am having trouble in figuring out why it is not returning the correct date. And it works correctly if I remove ([\s.\w]*) from the pattern. But I need them to further extract the time and AM or PM which can be optional in strContent.
I appreciate the help and thanks in advance.
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions
Sub Main()
Module Module1
dim strContent as string = "Scheduling Conference set for 7/30/2002 at 11:00 AM judge"
dim sPattern as string= "(?<FirstDate>(\d{1,2}[/-]\d{1,2}/-?\d\d))([\s.\w]*)"
Dim mx As Match = MatchStringForLastMatch(strContent, sPattern)
MsgBox(mx.Groups("FirstDate").Value)
End sub
Function MatchStringForLastMatch(ByRef sString As String, ByVal PatternString As String) As Match
'Returns the last match and the match Index
Dim DigitRegex As Regex = New Regex(PatternString, RegexOptions.IgnoreCase Or RegexOptions.Compiled Or RegexOptions.RightToLeft)
Dim Mx As Match = DigitRegex.Match(sString)
If Not DigitRegex Is Nothing Then DigitRegex = Nothing
Return Mx
End Function
'---------------------
End Module