Re: preg_match and dates
| From: | Per Jessen | Date: | Mon, 02 Mar 2009 10:22:02 +0000 |
| Subject: | Re: preg_match and dates | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-289037@lists.php.net to get a copy of this message | ||
Michael A. Peters wrote:
This is what I have so far - $pattern[] = "/^([0-9]{1,2})[\s-]([A-Z][a-z]*)[\s-]([0-9]{4,4})$/i"; $clean[] = "\\3-\\2-\\1"; $pattern[] = "/^([A-Z][a-z]*)[\s-]([0-9]{4,4})$/"; $clean[] = "\\2-\\1-01"; $foo = preg_replace($pattern, $clean, $verb_date);If I were you, I'd write several regexes, one for each date format you wish to recognize. It makes the regexes much easier to read, and you can still write sub-expressions for catching e.g. months and then reuse those in your main regexes. /Per Jessen