Home >Backend Development >PHP Tutorial >【初学者有关问题】一个简单正则表达式

【初学者有关问题】一个简单正则表达式

WBOY
WBOYOriginal
2016-06-13 10:06:52892browse

【菜鸟问题】一个简单正则表达式。
1421.87GB ,435Gb 
求一个正则表达式匹配:开头的数字,可能是小数也可能是整数。

------解决方案--------------------

PHP code
$str    = "1421.87GB ,435Gb";preg_match_all('/[\d]+(\.[\d]+)?/', $str, $m);print_r($m[0]);/*Array(    [0] => 1421.87    [1] => 435)*/<div class="clear">
                 
              
              
        
            </div>
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