Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要使用正则表达式从以下字符串中提取数字:
电脑 32444 xbox 43567
所以我的数组将是
array ([0] => 32444 [1] => 43567)
有人可以帮我构建一个 preg_match 吗?
谢谢!
试试这个正则表达式:
/\d+/
但是您需要使用preg_match_all来获取所有匹配项:
preg_match_all
preg_match_all('/\\d+/', $str, $matches)
$matches[0]然后将包含您要查找的数组。
$matches[0]