in reply to Re: what is the best way to seperate the digits and strings from variable ?
in thread what is the best way to seperate the digits and strings from variable ?
Please, test your code.
\d* will match 0 (ZERO) or more digits.
Thus, it will happily match an empty string at the beginning of a string like "abc123" and return a 0 length string. Try it.
The right expression to use in this case is \d+.
Moreover, a capturing regular expression should always be used with a test:
my $num; my $variable = "abc123"; if ( $variable =~ /(\d+)/) { $num = $1; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: what is the best way to seperate the digits and strings from variable ?
by polettix (Vicar) on May 09, 2005 at 13:04 UTC | |
by Tanktalus (Canon) on May 09, 2005 at 14:39 UTC | |
by polettix (Vicar) on May 09, 2005 at 15:46 UTC | |
by rnahi (Curate) on May 09, 2005 at 19:37 UTC | |
| |
Re^3: what is the best way to seperate the digits and strings from variable ?
by Errto (Vicar) on May 10, 2005 at 02:49 UTC |
In Section
Seekers of Perl Wisdom