RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
(?'DateLiteral' (?# Per the VB Spec : DateLiteral ::= '#' [ Whitespace+ ] DateOrTime [ Whitespace+ ] '#' ) \#\s* (?'DateOrTime' (?# DateOrTime ::= DateValue Whitespace+ TimeValue | DateValue | TimeValue ) (?'DateValue' (?# DateValue ::= Whitespace+ TimeValue | DateValue | TimeValue ) ( (?# DateValue ::= MonthValue / DayValue / YearValue | MonthValue - DayValue - YearValue ) (?'Month'(0?[1-9])|1[0-2]) (?# Month 01 - 12 ) (?'Sep'[-/]) (?# Date separator '-' or '/' ) (?'Day'0?[1-9]|[12]\d|3[01]) (?# Day 01 - 31 ) \k'Sep' (?# whatever date separator was previously matched ) (?'Year'\d{1,4}) \s+ (?# TimeValue ::= HourValue : MinuteValue [ : SecondValue ] [ WhiteSpace+ ] [ AMPM ] ) (?'HourValue'(0?[1-9])|1[0-9]|2[0-4]) (?# Hour 01 - 24 ) [:] (?'MinuteValue'0?[1-9]|[1-5]\d|60) (?# Minute 01 - 60 ) [:] (?'SecondValue':0?[1-9]|[1-5]\d|60)? (?# Optional Minute :01 - :60 ) \s* (?'AMPM'[AP]M)? ) | ( (?# DateValue ::= MonthValue / DayValue / YearValue | MonthValue - DayValue - YearValue ) (?'Month'(0?[1-9])|1[0-2]) (?# Month 01 - 12 ) (?'Sep'[-/]) (?# Date separator '-' or '/' ) (?'Day'0?[1-9]|[12]\d|3[01]) (?# Month 01 - 31 ) \k'Sep' (?# whatever date separator was previously matched ) (?'Year'\d{4}) ) | ( (?# TimeValue ::= HourValue : MinuteValue [ : SecondValue ] [ WhiteSpace+ ] [ AMPM ] ) (?'HourValue'(0?[1-9])|1[0-9]|2[0-4]) (?# Hour 01 - 24 ) [:] (?'MinuteValue'0?[1-9]|[1-5]\d|60) (?# Minute 01 - 60 ) [:] (?'SecondValue':0?[1-9]|[1-5]\d|60)? (?# Optional Minute :01 - :60 ) \s* (?'AMPM'[AP]M)? ) ) ) \s*\# )
Description
Match the VB Language specification BNF for DateTime literal. 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
Matches
# 8/23/1970 3:45:39AM # | # 8/23/1970 #
Non-Matches
## | # 23/8/1970 #
Author Rating: The rating for this expression. Darren Neimke
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Ranges
Name: Michael Ash
Date: 3/30/2004 11:21:54 AM
Comment:
While this regex is a good format match the ranges it accepts are a little scewed. Most notablely the time which will accept 24:60:60 but not 4:00AM.


Title: re: Can compress some of the subexprs
Name: Michael Ash
Date: 3/30/2004 10:44:49 AM
Comment:
Actually (?'Day'0?[1-9]|[12]\d|3[01]) and (?'Day'[012]?\d|3[01]) are not exactlly the same. The latter will accept 0 and 00? which aren't valid for the expression


Title: Can compress some of the subexprs
Name: Eric
Date: 3/30/2004 9:32:43 AM
Comment:
One refinement... on the numeric parts (day/hour etc) you can combine some of the expressions: (?'Day'0?[1-9]|[12]\d|3[01]) => (?'Day'[012]?\d|3[01]) since (in this case) only 3 needs to be special-cased; the subexpressions for 0 and for 1-2 were identical. The same thing can be done for hours, minutes, and seconds. I don't know if it will make any difference performance wise (I suspect not), but it is a little more succinct.


Title: Thanks to the Regulator
Name: Darren Neimke
Date: 3/30/2004 7:28:06 AM
Comment:
I should mention that The Regulator was invaluable while building this expression: http://royo.is-a-geek.com/iserializable/regulator/ The syntax coloring and the friendly display of Named Captures was very useful as I worked on the pattern. Thanks Royo! :-)


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials