There's more than one way to do things | |
PerlMonks |
Re: Regex problem - (non)greedy?by hdb (Monsignor) |
on Nov 14, 2013 at 14:29 UTC ( [id://1062592]=note: print w/replies, xml ) | Need Help?? |
The non-greedy regex would still start at the first occurence of 'cd' but then stop at the first 'ghi', whereas the greedy one would stop at the last 'ghi'. (In your example there is only one, so they are the same.) You can use this behavior to achieve the desired effect by adding something greedy before the expression of interest, like
Here the .* at the beginning would eat up everything up the last occurrence of 'cd', which is what you want.
In Section
Seekers of Perl Wisdom
|
|