Codice PHP:
$stringa "123stringablabla";
preg_match("/^[0-9]*/",$stringa,$match);
echo 
$match[0];