开发者

Extract numbers from text with regular expression

开发者 https://www.devze.com 2023-01-14 19:32 出处:网络
I am trying to extract 1 and 125 from this text开发者_如何学编程 with PHP: preg_match(\"/^(?P<digit>\\d+)/\", \"1 Foo ($125)\",$m)

I am trying to extract 1 and 125 from this text开发者_如何学编程 with PHP:

preg_match("/^(?P<digit>\d+)/", "1 Foo ($125)",$m)

Can you please help?

Thanks


Try this:

<?php
preg_match_all('/\d+/', '1 Foo ($125) bar', $matches);
var_dump($matches);
?>

Note that I used preg_match_all which literally returns all matches in the pattern.

0

精彩评论

暂无评论...
验证码 换一张
取 消