Well, MRE doesn't say that those regexen are to be used to find integers -- in fact, it states: 'We don't know what these might be used for ...'.
However, if you do want to find (and extract) just integers you could employ both negative look-ahead, and negative look-behind (lookhind wasn't available when MRE was written):
my $numbers="1 1.0 3.547 123 92.34 343.2234"; while($numbers=~/(?<![\d.])(\d+)(?![\d.])/g){ print "$1 is an integer\n"; }
That says: match a bunch of digits that are not preceded by a digit or a dot, and are not followed by a digit or a dot (there be other particular exceptions that I'm not considering at the moment such as grabbing any leading + or - sign if present, but this gives you something to play with).
Update: Ahh, and an important exception I neglected is caught by mirod's version: namely, an integer could occur at the end of a sentence and be legitimately followed by a dot, thus we may want to allow for a trailing dot as long as it isn't followed by digits by changing the negative look-ahead above to the one mirod uses: (?!\d*\.\d).
In reply to Re: How can I match all the integers in a string?
by danger
in thread How can I match all the integers in a string?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |