473,395 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Regular Expression Matching in ANSI ?

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 )
{}
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
5 2028
poi <dd****@rucs.nul> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2
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" <dd****@rucs.nul> wrote in message
news:uV*************@TK2MSFTNGP12.phx.gbl...


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 )
{}
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #3
Chris hasn't seen this post yet? :-)
"Ross Donald" <ro**@radsoftware.com.auNOSPAM> wrote in message
news:#y**************@TK2MSFTNGP12.phx.gbl...
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" <dd****@rucs.nul> wrote in message
news:uV*************@TK2MSFTNGP12.phx.gbl...


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 )
{}
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 15 '05 #4
Errr.... who is Chris? and what would he say about that post?

--
Ross Donald
Rad Software
"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
message news:uk**************@tk2msftngp13.phx.gbl...
| Chris hasn't seen this post yet? :-)
| "Ross Donald" <ro**@radsoftware.com.auNOSPAM> wrote in message
| news:#y**************@TK2MSFTNGP12.phx.gbl...
| > 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" <dd****@rucs.nul> wrote in message
| > news:uV*************@TK2MSFTNGP12.phx.gbl...
| > >
| > >
| > > 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 )
| > > {}
| > >
| > >
| > > *** Sent via Developersdex http://www.developersdex.com ***
| > > Don't just participate in USENET...get rewarded for it!
| >
| >
|
|
Nov 15 '05 #5
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" <ro**@radsoftware.com.auNOSPAM> wrote in message
news:#c*************@tk2msftngp13.phx.gbl...
Errr.... who is Chris? and what would he say about that post?

--
Ross Donald
Rad Software
"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
message news:uk**************@tk2msftngp13.phx.gbl...
| Chris hasn't seen this post yet? :-)
| "Ross Donald" <ro**@radsoftware.com.auNOSPAM> wrote in message
| news:#y**************@TK2MSFTNGP12.phx.gbl...
| > 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" <dd****@rucs.nul> wrote in message
| > news:uV*************@TK2MSFTNGP12.phx.gbl...
| > >
| > >
| > > 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 )
| > > {}
| > >
| > >
| > > *** Sent via Developersdex http://www.developersdex.com ***
| > > Don't just participate in USENET...get rewarded for it!
| >
| >
|
|

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
5
by: Avi Kak | last post by:
Folks, Does regular expression processing in Python allow for executable code to be embedded inside a regular expression? For example, in Perl the following two statements $regex =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.