Hi,
I was wondering if it's possible to capture subpatterns in PHP regular expressions. For example, the following PERL code will capture the State information from the string's subpattern.
$string = "San Diego, CA";
$string =~ m/\,\s(\w{2})$/i;
$state = $1;
print $state; #prints "CA"
print $string; #prints "San Diego, CA"
Does anyone know an equivalent way to do this in PHP?
thanks,
Phu
P.S.
I know that the PHP code below will work, but it will also replace $string with the State subpattern.
$state = preg_replace( "/\,\s(\w{2})$/ei", "\$state = '\1'", $string);
echo $state; //prints "CA"
echo $string; //prints "CA"