|
-
Jul 17th, 2007, 04:30 PM
#1
Thread Starter
No place like 127.0.0.1
Need regular expression that matches any date acceptable by strtotime()
Hey all.
I was wondering if anyone knew of where I could find a regular expression that would match any date that is acceptable by strtotime().
Here is what I have so far (not complete by any means):
PHP Code:
'#((([0-3]?[0-9](st|nd|rd|th)?
)?(Jan(uary)?|Feb(ruary)?|Mar(ch)?|Apr(il)?|May|Ju((ly?)|
(ne?))|Aug(ust)?|Oct(ober)?|(Sept|Nov|Dec)(ember)?)
)?(18|19|20)[0-9]{2})#i'
This will match any of the following:
21 Aug 1998
Aug 1998
1998
21st August 1998
... And any combination of variations you can think of in there.
The problem is, strtotime() can take MANY more date formats and I want to be able to match all of them and I'm not too skilled at regular expressions. I could probably come up with one, but it would be miles long just to account for every case. I'm sure someone else could come up with a more elegant one.
Any ideas?
-
Jul 17th, 2007, 04:34 PM
#2
Thread Starter
No place like 127.0.0.1
Re: Need regular expression that matches any date acceptable by strtotime()
Hmmm. I might have found part of the answer:
http://regexlib.com/REDetails.aspx?regexp_id=113
That doesn't match DD mmm YYYY or DD mmmmmm YYYY, though.
-
Jul 18th, 2007, 12:18 AM
#3
Re: Need regular expression that matches any date acceptable by strtotime()
Why don't you use strtotime to see if it is valid?
PHP Code:
$date = strtotime($datestring);
if ($date !== false)
// valid
else
// invalid
-
Jul 18th, 2007, 12:37 AM
#4
Thread Starter
No place like 127.0.0.1
Re: Need regular expression that matches any date acceptable by strtotime()
Because I need to use preg_match_all() on a paragraph of text that could contain any type of date.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|