in reply to Pattern matching: Lazy vs. greedy
You can stick a greedy quantifier before your non-greedy match. That way the greedy quantifier will eat up as much as it can while the non-greedy part will still match. You seem to call "lazy" what the Perl documentation calls "non-greedy" in perlre.
#!/usr/bin/perl -w use strict; my $string = "The quick brown fox jumps over the lazy dog"; $string =~ /.*(the .*? dog)/i; print "Match: '", $1, "'"; __END__ Match: 'the lazy dog'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pattern matching: Lazy vs. greedy
by false_friend (Novice) on Mar 30, 2015 at 09:14 UTC |