PHP 中的正则表达式
RegExpre in PHP
我想搜索 3 个数字(可选小数位),我尝试使用
preg_match()
在 PHP 中,但没有过滤器使用正则表达式 /^\d{1,3}([,.]\d)?$/
输入:
8631.0
输出:
array (size=2)
0 => string '368.6' (length=5)
1 => string '.6' (length=2)*
您的正则表达式需要修改,请试试这个:-
preg_match('/^[0-9]{3}+(\.[0-9]{1})?$/', "631.0",$matchess));
echo "<pre/>";print_r($matchess);
输出:- http://prntscr.com/754920
再次:-
preg_match('/^[0-9]{3}+(\.[0-9]{1})?$/', "8631.0",$matchess));
echo "<pre/>";print_r($matchess);
输出:- http://prntscr.com/7549g4
注意:- 您使用了 var_dump,而我使用了 print_r,以便以更好、更易于理解的方式显示。
我想搜索 3 个数字(可选小数位),我尝试使用
preg_match()
在 PHP 中,但没有过滤器使用正则表达式 /^\d{1,3}([,.]\d)?$/
输入:
8631.0
输出:
array (size=2)
0 => string '368.6' (length=5)
1 => string '.6' (length=2)*
您的正则表达式需要修改,请试试这个:-
preg_match('/^[0-9]{3}+(\.[0-9]{1})?$/', "631.0",$matchess));
echo "<pre/>";print_r($matchess);
输出:- http://prntscr.com/754920
再次:-
preg_match('/^[0-9]{3}+(\.[0-9]{1})?$/', "8631.0",$matchess));
echo "<pre/>";print_r($matchess);
输出:- http://prntscr.com/7549g4
注意:- 您使用了 var_dump,而我使用了 print_r,以便以更好、更易于理解的方式显示。