genghis has asked for the wisdom of the Perl Monks concerning the following question:
I'm confused about assigning the results of regex matches to variables. An example from the Perl Cookbook (works, of course):
my $string1 = '123456789'; my @nonlap = $string1 =~/(\d\d\d)/g; #nonlap now contains (123,456,789)
But this time, when I try to pull out 81 from the string A81, it doesn't do what I expected (Regex Coach shows that it's matching both numbers):
my $string2 = 'A81'; my $digits = $string2 =~ /(\d)+/; #$digits now contains '1'
Thanks for your help...
.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: assigning regex matches to variables
by CountZero (Bishop) on May 28, 2011 at 20:22 UTC | |
|
Re: assigning regex matches to variables
by luis.roca (Deacon) on May 28, 2011 at 21:20 UTC | |
|
Re: assigning regex matches to variables
by jwkrahn (Abbot) on May 28, 2011 at 20:28 UTC | |
|
Re: assigning regex matches to variables
by lidden (Curate) on May 28, 2011 at 20:10 UTC | |
by JavaFan (Canon) on May 28, 2011 at 20:22 UTC | |
by genghis (Novice) on May 28, 2011 at 20:26 UTC | |
by jwkrahn (Abbot) on May 28, 2011 at 20:33 UTC | |
|
Re: assigning regex matches to variables
by genghis (Novice) on May 28, 2011 at 21:08 UTC | |
by jethro (Monsignor) on May 28, 2011 at 21:23 UTC |