gregor-e has asked for the wisdom of the Perl Monks concerning the following question:
I'd like this example to extract the name/address record for user #2, Bizzi Buddi, so I attempt to grab everything from "name" to "user: 2". Unfortunately, this regex is not minimally greedy, despite the .*?, and ends up matching the preceeding record also, which contains "name". How can I create a regex that minimally matches /literal_1.*literal_2/ and guarantees that the first literal is not repeated within the wildcard?#! /usr/local/bin/perl my $source = " name: Schwank E. Schwagg address: 123 Dirtweed Dr. user: 1 name: Bizzi Buddi address: 321 Grapevine Way user: 2 name: Fernal Brimstone address: 666 Lucifer Ln user: 3 "; $source =~ m/.*?(name.*?user: 2)/s; print "$1\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: minimal greed
by neshura (Chaplain) on Feb 16, 2000 at 01:12 UTC | |
|
Re: minimal greed
by japhy (Canon) on Feb 16, 2000 at 19:44 UTC | |
|
Re: minimal greed
by chromatic (Archbishop) on Feb 16, 2000 at 03:01 UTC | |
|
Re: minimal greed
by jcouto (Novice) on Feb 16, 2000 at 15:27 UTC | |
|
Re: minimal greed
by Crulx (Monk) on Feb 16, 2000 at 14:48 UTC |