当前位置:Gxlcms > PHP教程 > 正则匹配指定长度的数字要如何写

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

时间:2021-07-01 10:21:17 帮助过:20人阅读

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

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

$str=<<1234567890
1234567890123
0987654321
3210987654321
1324354657
1324354657689
htm;

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

------解决方案--------------------
PHP code
1234567890
1234567890123
0987654321
3210987654321
1324354657
1324354657689
htm;

preg_match_all('/([\d]{10}\b<\/td>)/',$str,$match);
print_R ($match[1]);

------解决方案--------------------
PHP code
preg_match_all('/(\d{10}\b)<\/td>/',$str,$matchs);
print_r ($matchs);

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

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

人气教程排行