in reply to How can I match all the integers in a string?
The OGRE would say (I'm paraphrasing): "make sure we're not preceded by a digit or a period, then, saving to $1, match (without backtracking) one or more digits, and then make sure we can't match a period and a digit." If we removed the cut operator, that \d+ could backtrack to say that in "123.456", the "12" part is found as an integer, which would be a false positive.$_ = "1 1.0 3.547 92.34 343.2234"; while (/(?<![\d.])((?>\d+))(?!\.\d)/g) { print "$1\n"; }
If you want, like mirod did, to match 1.0 as an integer, you would change this to:
/(?<![\d.])((?>\d+(?:\.0+)?))(?!\.\d)/g
|
|---|