字符串是“lorem,ipsum 12 dolorem,si amet 58,14”等。我需要提取“12”和“58,14”。我没有定期的解释经验。所以问题是-我该怎么做?:) 语言(如果这很重要)是php5。
<?php $foundMatches = array(); $targetString = "Lorem, ipsum 12 dolorem, si amet 58,14"; preg_match_all('/([1-9]\d*|0)(,\d+)?/', $targetString, $foundMatches); var_dump($foundMatches); ?>
您可以在以下网址找到所需的结果: $foundMatches[0] .
$foundMatches[0]
编辑:更新的regex不匹配 123, 或 012 . 如果你想要那些用老的 /\d+,?\d*?/ .
123,
012
/\d+,?\d*?/
有用的阅读: http://www.regular-expressions.info/