如何regexp PHP查找字符串中的数字
我对regexp有问题,我正在寻找解决这个问题的方法 我需要在文本中查找超过3位的数字,但我需要忽略数字在开始/最后$字符上的位置 示例: Lorem ipsum dolor32sit32181527amet,Concertetur Adipising18312.90美元,2432417美元 关于结果,我只想得到这个数字32181527 我知道如何获取数字,但当is$出现时,我不能忽略如何regexp PHP查找字符串中的数字,php,regex,string,split,preg-match-all,Php,Regex,String,Split,Preg Match All,我对regexp有问题,我正在寻找解决这个问题的方法 我需要在文本中查找超过3位的数字,但我需要忽略数字在开始/最后$字符上的位置 示例: Lorem ipsum dolor32sit32181527amet,Concertetur Adipising18312.90美元,2432417美元 关于结果,我只想得到这个数字32181527 我知道如何获取数字,但当is$出现时,我不能忽略 [0-9]{3,} 使用,可以限制不在特定模式之前/之后的匹配: $text = "Lorem ipsum
[0-9]{3,}
使用,可以限制不在特定模式之前/之后的匹配:
$text = "Lorem ipsum dolor 32 sit 32181527 amet, consectetur adipiscing $18312.90, 2432417$.";
preg_match_all('/(?<![0-9$])[0-9]{3,}(?![0-9$])/', $text, $matches);
// match 3+ digits which is not preceded by digits/$.
// also the digits should not be followed by digits/$.
print_r($matches);
Array
(
[0] => Array
(
[0] => 32181527
)
)