Using BNF to create regex's
While reading the VB Language Spec today I decided to attempt to follow the grammar syntax for matching DateTime Literals:
http://msdn.microsoft.com/library/en-us/vbls7/html/vblrfvbspec2_4_6.asp?frame=true
DateLiteral ::= # [ Whitespace+ ] DateOrTime [ Whitespace+ ] # DateOrTime ::= DateValue Whitespace+ TimeValue | DateValue | TimeValue DateValue ::= MonthValue / DayValue / YearValue | MonthValue – DayValue - YearValue TimeValue ::= HourValue : MinuteValue [ : SecondValue ] [ WhiteSpace+ ] [ AMPM ] MonthValue ::= IntLiteral DayValue ::= IntLiteral YearValue ::= IntLiteral HourValue ::= IntLiteral MinuteValue ::= IntLiteral SecondValue ::= IntLiteral AMPM ::= AM | PM
The resulting pattern can be seen (fully commented) here:
http://www.regexlib.com/REDetails.aspx?regexp_id=638