php 正则表达式 提取字符串内小括号中的数字,只要数字

2024-11-02 01:22:52
推荐回答(4个)
回答1:

$str="一二三四五ABN420122(电话:123455)";
$reg= '/.*\(.*:(.*)\)/';//冒号和$str保持一致
$reg= '/.*\(.*(\d{6,})\)/';
$reg= '/.*\(.*[^\d](\d+)\)/';
preg_match_all($reg,$str,$want);
print_r($want[1]);

3种正则 都可以

回答2:

preg_match_all('/(电话:\d*)/i',$str,$str_ary);
如果不想用“电话这种汉字”
preg_match_all("/\((.*\d+)/i",$str,$str_ary);

回答3:

$str="一二三四五ABN420122(电话:123455)";
preg_match_all("/[^\(]*\(\D*(\d*).*/i",$str,$str_ary);
var_export($str_ary);
exit;

回答4:

preg_match_all("/(.*)[(](.*)(\d*)[)](.*)/isU", $str, $str_ary);