从字符串php捕获日期短语

I have the strings (in an array):

$a = "account Tel48201389 user@whatever.net dated 2013-07-01 in JHB".

and

$b = "installation on 2013-08-11 in PE".

I need to get the full date out of each of these strings using PHP only.
is it possible to use wildcards with pregmatch?
i tried:

preg_match('/(?P<'name'>\w+): (?P'<'digit-digit-digit'>'\d+)/', $str, $matches); 

but it gives an error.
end result should be: $a = 2013-07-01" and $b = "2013-08-11" THanks!

You can use preg_match_all to get all date patter in an string. All string matches will be saved in an array which should be passed as an argument to the function.

In this example save all patterns dddd-dd-dd in the array $matches.

$string = "account Tel48201389 user@whatever.net dated 2013-07-01 in JHB installation on 2013-08-11 in PE";

if (preg_match_all("@\d{4}-\d{2}-\d{2}@", $string, $matches)) {
   print_r($matches);
}

Good luck!

 $a = "account Tel48201389 user@whatever.net dated 2013-07-01 in JHB";

    if(preg_match('%[0-9]{4}+\-+[0-9]{2}+\-[0-9]{2}%',$a,$match)) {

    print_r($match);    

    }

Should work for both strings - if date always will be in this format.

You can do this.

<?php
$b = 'installation on 2013-08-11 in PE';
preg_match('#([0-9]{4}-[0-9]{2}-[0-9]{2})#', $b, $matches);
if (count($matches) == 1) {
    $b = $matches[0];
    echo $b; # 2013-08-11
}
?>

Try this....

 $a = "account Tel48201389 user@whatever.net dated 2013-07-01 in JHB";

 preg_match("/(?P<year>[0-9]{4})-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})/", $a, $matches);

 if($matches){
 echo $matches[0];// For the complete string
 echo $matches['year'];//for just the year etc
 }