Regular Expression Matching in ANSI ?

P

poi

I found this regex on the web and it takes dates as MM/DD/YYYY. I need
it to take dates as YYYY-MM-DD but can't see how, can anyone point me in
the right direction?


System.Text.RegularExpressions.Match dateMatch;
System.Text.RegularExpressions.Regex dateTest =
new Regex(
@"^((((((0?[13578])|(1[0-2]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|
(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((
0?[1-9])|([1-2][0-9]))))[\-\/\s]?\d{2}(([02468][048])|([13579][26])))|((
(((0?[13578])|(1[0-2]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[
469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9
])|(1[0-9])|(2[0-8]))))[\-\/\s]?\d{2}(([02468][1235679])|([13579][013457
89]))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([
AM|PM|am|pm]{2,2})))?$" );
dateMatch = dateTest.Match( this.txtDateofLoss.Text.Trim() );
if ( dateMatch.Success == false )
{}
 
J

Jon Skeet

poi said:
I found this regex on the web and it takes dates as MM/DD/YYYY. I need
it to take dates as YYYY-MM-DD but can't see how, can anyone point me in
the right direction?

<snip 8 lines of regular expression>

Why not just use DateTime.ParseExact instead? A regular expression like
that is *always* going to be a nightmare to read.
 
R

Ross Donald

Hi,

I'm not touching that one!

http://www.regexlib.com has many pre-written regular expressions. You should
be able to find something there.

If not, a very simple starting point would be

^\d{4}-[01][0-9]-[0-3][0-9]$
 
A

Alvin Bruney

Chris hasn't seen this post yet? :)
Ross Donald said:
Hi,

I'm not touching that one!

http://www.regexlib.com has many pre-written regular expressions. You should
be able to find something there.

If not, a very simple starting point would be

^\d{4}-[01][0-9]-[0-3][0-9]$

--
Ross Donald
Rad Software
Free Regular Expression Designer @
http://www.radsoftware.com.au/web/Products/


poi said:
I found this regex on the web and it takes dates as MM/DD/YYYY. I need
it to take dates as YYYY-MM-DD but can't see how, can anyone point me in
the right direction?


System.Text.RegularExpressions.Match dateMatch;
System.Text.RegularExpressions.Regex dateTest =
new Regex(
@"^((((((0?[13578])|(1[0-2]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|
(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((
0?[1-9])|([1-2][0-9]))))[\-\/\s]?\d{2}(([02468][048])|([13579][26])))|((
(((0?[13578])|(1[0-2]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[
469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9
])|(1[0-9])|(2[0-8]))))[\-\/\s]?\d{2}(([02468][1235679])|([13579][013457
89]))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([
AM|PM|am|pm]{2,2})))?$" );
dateMatch = dateTest.Match( this.txtDateofLoss.Text.Trim() );
if ( dateMatch.Success == false )
{}
 
R

Ross Donald

Errr.... who is Chris? and what would he say about that post?

--
Ross Donald
Rad Software


message | Chris hasn't seen this post yet? :)
| | > Hi,
| >
| > I'm not touching that one!
| >
| > http://www.regexlib.com has many pre-written regular expressions. You
| should
| > be able to find something there.
| >
| > If not, a very simple starting point would be
| >
| > ^\d{4}-[01][0-9]-[0-3][0-9]$
| >
| > --
| > Ross Donald
| > Rad Software
| > Free Regular Expression Designer @
| > http://www.radsoftware.com.au/web/Products/
| >
| >
| > | > >
| > >
| > > I found this regex on the web and it takes dates as MM/DD/YYYY. I
need
| > > it to take dates as YYYY-MM-DD but can't see how, can anyone point me
in
| > > the right direction?
| > >
| > >
| > > System.Text.RegularExpressions.Match dateMatch;
| > > System.Text.RegularExpressions.Regex dateTest =
| > > new Regex(
| > >
@"^((((((0?[13578])|(1[0-2]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|
| > >
(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((
| > >
0?[1-9])|([1-2][0-9]))))[\-\/\s]?\d{2}(([02468][048])|([13579][26])))|((
| > >
(((0?[13578])|(1[0-2]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[
| > >
469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9
| >
])|(1[0-9])|(2[0-8]))))[\-\/\s]?\d{2}(([02468][1235679])|([13579][013457
| > >
89]))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([
| > > AM|PM|am|pm]{2,2})))?$" );
| > > dateMatch = dateTest.Match( this.txtDateofLoss.Text.Trim() );
| > > if ( dateMatch.Success == false )
| > > {}
| > >
| > >
| > >
| > > Don't just participate in USENET...get rewarded for it!
| >
| >
|
|
 
A

Alvin Bruney

he loves regex stuff, he can whip you out an answer. or check regexlib.com
or eric gu's site for a solution
Ross Donald said:
Errr.... who is Chris? and what would he say about that post?

--
Ross Donald
Rad Software


message | Chris hasn't seen this post yet? :)
| | > Hi,
| >
| > I'm not touching that one!
| >
| > http://www.regexlib.com has many pre-written regular expressions. You
| should
| > be able to find something there.
| >
| > If not, a very simple starting point would be
| >
| > ^\d{4}-[01][0-9]-[0-3][0-9]$
| >
| > --
| > Ross Donald
| > Rad Software
| > Free Regular Expression Designer @
| > http://www.radsoftware.com.au/web/Products/
| >
| >
| > | > >
| > >
| > > I found this regex on the web and it takes dates as MM/DD/YYYY. I
need
| > > it to take dates as YYYY-MM-DD but can't see how, can anyone point me
in
| > > the right direction?
| > >
| > >
| > > System.Text.RegularExpressions.Match dateMatch;
| > > System.Text.RegularExpressions.Regex dateTest =
| > > new Regex(
| > >
@"^((((((0?[13578])|(1[0-2]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|
| > >
(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((
| > >
0?[1-9])|([1-2][0-9]))))[\-\/\s]?\d{2}(([02468][048])|([13579][26])))|((
| > >
(((0?[13578])|(1[0-2]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[
| > >
469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9
| >
])|(1[0-9])|(2[0-8]))))[\-\/\s]?\d{2}(([02468][1235679])|([13579][013457
| > >
89]))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([
| > > AM|PM|am|pm]{2,2})))?$" );
| > > dateMatch = dateTest.Match( this.txtDateofLoss.Text.Trim() );
| > > if ( dateMatch.Success == false )
| > > {}
| > >
| > >
| > >
| > > Don't just participate in USENET...get rewarded for it!
| >
| >
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top