Google Answers Logo
View Question
 
Q: write a set of regular expressions tha regconise dates ( Answered,   1 Comment )
Question  
Subject: write a set of regular expressions tha regconise dates
Category: Computers > Programming
Asked by: kazami-ga
List Price: $2.00
Posted: 03 May 2003 18:11 PDT
Expires: 02 Jun 2003 18:11 PDT
Question ID: 199033
write a set of regular expressions tha regconise dates in normal text.
eg 12th February 2002, is a date, so is 03/02/2002, and so is 4
Mar'02. there are a lot of different ways dates can be recognised.
And use the egrep in linux

Request for Question Clarification by coral-ga on 04 May 2003 14:04 PDT
There's thousands of ways to format dates; writing that regex properly
for you could take days upon days upon days.  Can you provide a list
of the date formats you'd most like recognized?  If so, I can write
the regex to those.

Clarification of Question by kazami-ga on 04 May 2003 16:24 PDT
12th February 2002
31th Jan 2002
03/02/2002
22/02/01
4 Mar'02
3-4-2002
3-4-02
14122002
July 1, 1995

thanks
Answer  
Subject: Re: write a set of regular expressions that recognise dates
Answered By: coral-ga on 04 May 2003 22:06 PDT
 
Here you go.  Tested compatible with egrep 2.5.1; it's too bad you
aren't using Perl, or this would look somewhat more readable :)  Were
you aware there's perl modules to handle this?  I'm available for
further work on this regex, if you'd like to understand it more fully
or improve it to support other dates; if interested, you should ask a
new question, referencing this question.

 - R.

((0?[1-9]|[1-2][0-9]|3[0-1])(st|nd|rd|th)?
+(Jan(uary)?|Feb(ruary)?|Mar(ch)?|Apr(il)?|May|Jun(e)?|Jul(y)?|Aug(ust)?|Sep(tember)?|Oct(ober)?|Nov(ember)?|Dec(ember)?)['
]+(19|20)?[0-9][0-9]|(0?[1-9]|1[0-2])[-/](0?[1-9]|[1-2][0-9]|3[0-1])[-/](19|20)?[0-9][0-9]|(0?[1-9]|[1-2][0-9]|3[0-1])[-/]([0-2][0-9]|3[0-1])[-/](19|20)?[0-9][0-9]|(0?[1-9]|[1-2][0-9]|3[0-1])([0-2][0-9]|3[0-1])(19|20)[0-9][0-9]|(Jan(uary)?|Feb(ruary)?|Mar(ch)?|Apr(il)?|May|Jun(e)?|Jul(y)?|Aug(ust)?|Sep(tember)?|Oct(ober)?|Nov(ember)?|Dec(ember)?)
+(0?[1-9]|[1-2][0-9]|3[0-1])(st|nd|rd|th)?(,)? +(19|20)[0-9][0-9])
Comments  
Subject: Re: write a set of regular expressions tha regconise dates
From: coral-ga on 04 May 2003 22:08 PDT
 
Hrm.  Google wrapped it at the space characters, which breaks the
regex.  I've posted a copy of it at
http://www.crystalflame.net/ga-199033/regex.txt in case it was
corrupted by the web form here.
 
Usage: egrep "..." *.txt  # replace ... with the regex.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy