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

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

WBOY
Release: 2016-06-13 13:46:32
Original
1044 people have browsed it

【菜鸟问题】一个简单正则表达式。
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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template