pbeckingham has asked for the wisdom of the Perl Monks concerning the following question:
Given a string that looks suspiciously like a path name:
yet is not a path name, I am trying to extract the abc000000 identifier from the end. My regex doesn't work, and while I know how to write a better one that works, I don't know specifically why this one does not:'/a/b/c/d/e/abc00000'
I can fix it easily by using:my $s = '/a/b/c/d/e/abc00000'; my ($id) = $s =~ m{/(.+?\d+)$}; print $id, "\n"; __OUTPUT__ a/b/c/d/e/abc00000
Which I understand. It's just that I don't understand why the first version is greedy.my ($id) = $s =~ m{/([^/]+\d+)$};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why is this regex greedy?
by chromatic (Archbishop) on Jul 02, 2004 at 20:32 UTC | |
by pbeckingham (Parson) on Jul 02, 2004 at 20:34 UTC | |
by duff (Parson) on Jul 02, 2004 at 20:55 UTC | |
|
Re: Why is this regex greedy?
by ercparker (Hermit) on Jul 02, 2004 at 20:28 UTC | |
by pbeckingham (Parson) on Jul 02, 2004 at 20:38 UTC | |
by mcogan1966 (Monk) on Jul 06, 2004 at 13:21 UTC | |
|
Re: Why is this regex greedy?
by dpavlin (Friar) on Jul 02, 2004 at 23:32 UTC | |
|
Re: Why is this regex greedy?
by kscaldef (Pilgrim) on Jul 03, 2004 at 00:15 UTC | |
|
Re: Why is this regex greedy?
by heroin_bob (Sexton) on Jul 03, 2004 at 01:51 UTC | |
|
Re: Why is this regex greedy?
by japhy (Canon) on Jul 03, 2004 at 02:50 UTC | |
|
Re: Why is this regex greedy?
by Stevie-O (Friar) on Jul 04, 2004 at 17:04 UTC |