From: Mukta Telang <mukta@...
> I want to extract decimal numbers from a string which contains blanks.
> There can be 0-2 such numbers inside the string. How to do this? I
> tried the following:
Don't use $&.
See $& section in
($one, $two) = /([0-9]+\.[0-9]+)/g;
or if you don't know how many numbers there'll be:
@numbers = /([0-9]+\.[0-9]+)/g;
The other problem is that this only accepts numbers with the decimal
part. If you also want to catch whole numbers you will want to change
the regexp to
@numbers = /([0-9]+(?:\.[0-9]+)?)/g;
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery