I have strings for date formats which will contain Y, M and D. For example some formats might be:
YY-MM-DD
M-D-Y G
MM/Y/DD
(etc)
I would like to run a regex match on strings like that and extract the Y, M, D in order. For example, in the above, I would like to have:
array('Y', 'M', 'D');
array('M', 'D', 'Y');
array('M', 'Y', 'D');
(etc)
I have written this regex expresion:
/(m+)|(d+)|(y+)/
But the issue is that it returns the whole match and not the first character like so:
array('YY', 'MM', 'DD');
array('M', 'D', 'Y');
array('MM', 'Y', 'D');
(etc)
How can I write my expression so that it only returns the first character?
Edit: some code (nothing complicated really).
$dates = array('YY-MM-DD', 'M-D-Y G', 'MM/Y/DD');
foreach($dates as $date){
preg_match_all('/(m+)|(d+)|(y+)/', strtolower($date), $matches);
var_dump($matches);
}