使用Regex分解单词/字符串中的值

i have this sample string and i want to explode the day,month,hour,minutes,(am/pm) wih regex:

SunDec 16 00:00am

Using this:

(\w+)\s+(\w+)\s+(\d+)\:(\d+)(..)

But it gives me:

Array
(
    [0] => SunDec 16 00:00am
    [1] => SunDec
    [2] => 16
    [3] => 00
    [4] => 00
    [5] => am
)

I cant figure it out..Can i explode SubDec into two?

You could try this:

$str = 'SunDec 16 00:00am';

preg_match('/([A-Z]{1}\w+)([A-Z]{1}\w+)\s+(\w+)\s+(\d+):(\d+)(..)/', $str, $ret);

print_r($ret);

If your string is always going to follow that example you can use this:

$string = 'SunDec 16 00:00am';
$pattern = '!([a-zA-Z]{3})([a-zA-Z]{3})\s+(\w+)\s+(\d+)\:(\d+)(..)!';
preg_match($pattern, $string, $chunks);
print_r($chunks);

Which outputs:

Array
(
    [0] => SunDec 16 00:00am
    [1] => Sun
    [2] => Dec
    [3] => 16
    [4] => 00
    [5] => 00
    [6] => am
)

You could use this pattern too which is slightly smaller

'!([a-z]{3})([a-z]{3})\s+(\w+)\s+(\d+)\:(\d+)(..)!i'

You can try this Regular Expression, This might help you

([A-Z][a-z]+)+\s(\d+)?\s?(\d+)\:(\d+)([a-z]+)