Home >Backend Development >PHP Tutorial >正则匹配指定长度的数字要如何写

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

WBOY
WBOYOriginal
2016-06-13 10:14:501261browse

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

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

------解决方案--------------------
PHP code
$str=1234567890<td>1234567890123</td><td>0987654321</td><td>3210987654321</td><td>1324354657</td><td>1324354657689</td>htm;preg_match('/(<td>[\d]{10})/',$str,$match);print_R ($match[1]);<br><font color="#e78608">------解决方案--------------------</font><br><dl class="code">PHP code<pre class="brush:php;toolbar:false"><?php $str=<<<htm<td>1234567890
12345678901230987654321321098765432113243546571324354657689htm;preg_match_all('/([\d]{10}\b)/',$str,$match);print_R ($match[1]);
------解决方案--------------------
PHP code
preg_match_all('/<td>(\d{10}\b)/',$str,$matchs);print_r ($matchs);<br><font color="#e78608">------解决方案--------------------</font><br>把函数改成 preg_match_all 就行了<br><br>preg_match_all('/(</td><td>[\d]{10})/',$str,$match);<br><br><div class="clear">
                 
              
              
        
            </div>
</td>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn