Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Results:my $numbers="1 1.0 3.547 92.34 343.2234"; while($numbers=~/(\d+)(?![\d.])/g){ print "$1 is an integer\n"; } print "-"x20,"\n"; while($numbers=~/(\d+)(?=[^.\d])/g){ print "$1 is an integer\n"; }
1 is an integer 0 is an integer 547 is an integer 34 is an integer 2234 is an integer -------------------- 1 is an integer 0 is an integer 547 is an integer 34 is an integer
Clearly I don't want to capture things that follow a decimal point. I tried prepending (^|[^.\d]) The front of each of these yet it didn't seem to help only made the results even more bizarre. Any suggestions?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How can I match all the integers in a string?
by danger (Priest) on Mar 04, 2001 at 12:50 UTC | |
|
Re: How can I match all the integers in a string?
by mirod (Canon) on Mar 04, 2001 at 13:06 UTC | |
|
Re: How can I match all the integers in a string?
by dvergin (Monsignor) on Mar 04, 2001 at 12:23 UTC | |
|
Re: How can I match all the integers in a string?
by japhy (Canon) on Mar 04, 2001 at 23:06 UTC |