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, |
In reply to Re: Pattern matching: Lazy vs. greedy
by Athanasius
in thread Pattern matching: Lazy vs. greedy
by false_friend
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |