首页 > 代码库 > php 正则提取数字

php 正则提取数字

<?php
//$patterns = "/^(http|https):\/\/(.)*\.(.)*$/";
$patterns = "/\d+/";
$strs="23345swwyuiopbfASWEDD4667";
preg_match_all($patterns,$strs,$arr);
print_r($arr);
?>

Array
(
    [0] => Array
        (
            [0] => 23345
            [1] => 4667
        )

)


<?php
//$patterns = "/^(http|https):\/\/(.)*\.(.)*$/";
$patterns = "/\d/";
$strs="23345swwyuiopbfASWEDD4667";
preg_match_all($patterns,$strs,$arr);
print_r($arr);
?>

Array
(
    [0] => Array
        (
            [0] => 2
            [1] => 3
            [2] => 3
            [3] => 4
            [4] => 5
            [5] => 4
            [6] => 6
            [7] => 6
            [8] => 7
        )

)

 

<?php

 
$str "sssefss$2345.1234dddfffeds$456$00.23RR";
 
$pattern ‘/\$(\d+\.?\d+)/‘;
 
if(preg_match_all($pattern$str$match)){
    echo ‘<pre>‘;
    print_r($match);
}else{
    echo ‘没有找到!‘;
}
 
结果:
Array
(
    [0] => Array
        (
            [0] => $2345.1234
            [1] => $456
            [2] => $00.23
        )
 
    [1] => Array
        (
            [0] => 2345.1234
            [1] => 456
            [2] => 00.23
        )
 
)

php 正则提取数字