Popcorn Dave has asked for the wisdom of the Perl Monks concerning the following question:
I know I'm probably going to slap my forehead after I get a response for this but...
I've got a very simple regex which I want to just pull sequential digits out of a filename which is passed in - e.g. sfytd13.txt should return 13.
I'm using the following code:
use strict; my $file = 'file013.txt'; my $sk = $file =~ m/\d+/; print $sk;
Very simple, but the problem is that I'm only getting the '1' back. I realize that if I use parthensis matching $1 will return '013' but I'm curious as to why my code doesn't return 13.
My understanding is that \d+ is going to match a digit followed by any number of digits until I hit a non-digit. What am I missing here? Is something getting clobbered in the assignment?
Thanks in advance!
There is no emoticon for what I'm feeling now.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex not behaving as expected
by Enlil (Parson) on Feb 01, 2003 at 00:38 UTC | |
by Popcorn Dave (Abbot) on Feb 01, 2003 at 00:48 UTC | |
|
Re: Regex not behaving as expected
by Paladin (Vicar) on Feb 01, 2003 at 00:33 UTC | |
|
Re: Regex not behaving as expected
by pizza_milkshake (Monk) on Feb 01, 2003 at 12:15 UTC | |
by pizza_milkshake (Monk) on Feb 01, 2003 at 12:21 UTC | |
by diotalevi (Canon) on Feb 01, 2003 at 16:47 UTC | |
by ihb (Deacon) on Feb 01, 2003 at 16:59 UTC | |
|
(elbie): Regex not behaving as expected
by elbie (Curate) on Feb 01, 2003 at 15:44 UTC | |
by ihb (Deacon) on Feb 01, 2003 at 16:30 UTC |