For the first time i am busy with Regex with PHP.
I want to make a licenseplate checker and put '-' between the letters and numbers. Everything works for now but the only one problem is that for every string i get another variable.
Like: for 999TB2 i get $1 $2 $3 but the second string 9999XX will be $4 $5 $6. Is it possible to get for the second string also $1 $2 $3?
<?php
$re = '/^(\d{3})([A-Z]{2})(\d{1})|(\d{2})(\d{2})([A-Z]{2})$/';
$str = '9999XX'; //(Will be later connected to database)
$subst = '$1-$2-$3 $4-$5-$6';
$result = preg_replace($re, $subst, $str, 1);
echo "The result of the substitution is ".$result;
?>
Kind regards