php regex用于字符串中的两个数字字符串

Ang*_*elo 0 php regex

我有以下内容

$data = "REFERENCE # 563005"
preg_match("/\d+/i", $data, $matches)
// $matches[0] will be set to 563005 with the above preg_match, however...
Run Code Online (Sandbox Code Playgroud)

$ data可能等于"REFERENCE#563005&563009&563125".在这些情况下,我需要一个正则表达式来检索数字的每个实例.所以,做一个preg_match会设置

$data = "REFERENCE # 563005 & 563009 & 563125"
preg_match("NEED REGEX", $data, $matches)
// $matches[0] would equal 563005, 
// $matches[1] would equal 563009, 
// $matches[2] would equal 563125, 
Run Code Online (Sandbox Code Playgroud)

取决于字符串中有多少个数字.这些数字可以是任意长度,数据字符串中最多可有10-20个这样的数字.

anu*_*ava 5

而不是preg_match您需要preg_match_all匹配输入中的所有数字:

preg_match_all('/\d+/', $data, $matches);
Run Code Online (Sandbox Code Playgroud)