in reply to Pattern matching: Lazy vs. greedy
Hello false_friend, and welcome to the Monastery!
Corion and LanX have answered your specific question, but, in the more general case, you might find it useful to be able to capture all possible matches:
#! perl use strict; use warnings; use Data::Dump; my $string = 'The quick brown fox jumps over the house of the lazy d +og'; my @matches = $string =~ /(?=(the .*? dog))/gi; dd \@matches;
Output:
19:36 >perl 1202_SoPW.pl [ "The quick brown fox jumps over the house of the lazy dog", "the house of the lazy dog", "the lazy dog", ] 19:37 >
You could then select the match(es) you want by greping @matches with suitable criteria. On the look-ahead assertion (?=...), see “Look-Around Assertions” in perlre#Extended-Patterns.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pattern matching: Lazy vs. greedy
by false_friend (Novice) on Mar 30, 2015 at 12:10 UTC | |
by choroba (Cardinal) on Mar 30, 2015 at 12:51 UTC | |
by false_friend (Novice) on Mar 30, 2015 at 17:47 UTC |