I need a PHP 5 regular expression for the following date/time format:
10 Jul 2010 15:00
(2 digits space 3 characters space 4 digits space 2 digits colon 2 digits)
Character case does not matter, and the only allowed input is a-z, 0-9, space, colon
Thanks in advance.
This matches exactly your specification, which allows anything as a month value.
As you can see, I’ve grouped each part of the date so you can easily reformat it.
If the string does not match, $m will be 0.
To ensure you only have valid months, you can use instead this regexp
But… now you only match english months.
This will soon become unwieldy. I strongly suggest you use a datetime handling library and let it handle all these issues.