I have the folling string:
$string = "16,1-5,22-27&22:1&4:3"
I want to get all numbers before the colon and return an array with them. So for the given string i would get the following:
array(22,4)
You can use this lookahead based regex in preg_match_all
:
\d+(?=:)
Code:
$str = "16,1-5,22-27&22:1&4:3";
preg_match_all('/\d+(?=:)/', $str, $matches);
print_r($matches[0]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句