in reply to Simple regular expression problem
Apart from the typos, the reason is that \w+ will gobble up all the word characters in $str, which includes the number at the end. Since your match specifies 'zero or more' numbers at then end, $num gets an empty string. You need to modify the regex to make the \w+ non-greedy, using the ? modifier:
my $str = "abdbdr23"; my ( $name, $num ) = ( $str =~ /^(\w+?)(\d*)$/ );
* is a much less ghastly way of writing {0,}.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Simple regular expression problem
by Perl Mouse (Chaplain) on Oct 03, 2005 at 14:14 UTC | |
by eric256 (Parson) on Oct 03, 2005 at 14:57 UTC | |
by Perl Mouse (Chaplain) on Oct 03, 2005 at 15:30 UTC | |
by eric256 (Parson) on Oct 03, 2005 at 16:31 UTC | |
by polypompholyx (Chaplain) on Oct 03, 2005 at 14:31 UTC | |
by jeanluca (Deacon) on Oct 03, 2005 at 14:59 UTC | |
Re^2: Simple regular expression problem
by ikegami (Patriarch) on Oct 03, 2005 at 14:40 UTC | |
by Dietz (Curate) on Oct 03, 2005 at 14:45 UTC | |
by ikegami (Patriarch) on Oct 03, 2005 at 14:47 UTC |