Capturing with nested parentheses : preg_match « String « PHP
- PHP
- String
- preg_match
Capturing with nested parentheses
<?
if (preg_match('/^(\d{5})(-(\d{4}))?$/',$_POST['zip'],$matches)) {
print "The beginning of the ZIP Code is: $matches[1]\n";
if (isset($matches[2])) {
print "The ZIP+4 is: $matches[3]";
}
}
?>
Related examples in the same category