正则匹配指定长度的数字要如何写

原创
2016-06-13 13:36:14 1123浏览

正则匹配指定长度的数字要怎么写?

1234567890
1234567890123
0987654321
3210987654321
1324354657
1324354657689
我只想匹配其中长度为10的那些数字,我要怎么写正则?

------解决方案--------------------
PHP code

$str=1234567890
1234567890123
0987654321
3210987654321
1324354657
1324354657689
htm;

preg_match('/([\d]{10})/',$str,$match);
print_R ($match[1]);

------解决方案--------------------
PHP code
1234567890
1234567890123 0987654321 3210987654321 1324354657 1324354657689 htm; preg_match_all('/([\d]{10}\b)/',$str,$match); print_R ($match[1]);
------解决方案--------------------
PHP code
preg_match_all('/(\d{10}\b)/',$str,$matchs);
print_r ($matchs);

------解决方案--------------------
把函数改成 preg_match_all 就行了

preg_match_all('/([\d]{10})/',$str,$match);

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。