字符串中提取数字--PHP或者正则

来源:百度知道 编辑:UC知道 时间:2024/07/03 04:30:12
用PHP或者正则如何从“1. 血红蛋白 (参考范围:男 120-160,女 110-150 g/l):158.27g/l”将120、160、110、150、158.27这5个数字提取出来!

<?php
$str = "1. 血红蛋白 (参考范围:男 120-160,女 110-150 g/l):158.27g/l";
$reg = '/(\d{3}(\.\d+)?)/is';//正则表达式
preg_match_all($reg,$str,$tmp);//匹配
print_r($tmp[1]);//$tmp[1]为匹配结果
?>

<?php
preg_match_all ("/\d{1,}/",
"1. 血红蛋白 (参考范围:男 120-160,女 110-150 g/l):158.27g/l",
$out, PREG_PATTERN_ORDER);
print_r($out);
?>