Aristotle has asked for the wisdom of the Perl Monks concerning the following question:
So I was just looking at Dominus’ Regular Expression Mastery talk, since I hadn’t seen it before. I’ve been around the block enough times to know the subject matter cold, but of course understanding and mastery are separate issues and it’s always good to take another look – in complex subjects, other people will often bring up angles to look at some of their aspects that you never thought of before. Anyway, I was skimming the slides, but it didn’t look like I’d be taking home anything from this talk.
Until I came to the absolute end, the very last bullet of the very last slide:
- Also there’s a non-greedy version X??
- I used to pay US$60 for a live sighting of ?? in the wild
- But one day I thought of
if ( $option =~ /^-f(i(e(ld??)??)??)??$/ ) { ... }
I’ve been staring at that example for 10 minutes and I really can’t see how it would ever match differently from the greedy version:
/^-f(i(e(ld?)?)?)?$/
From what I can tell, since the entire pattern is anchored at both ends and the captures are nested, it must always match the exact same things, whether the quantifiers are greedy or not.
Am I missing something?
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dominus on the non-greedy version of the ? quantifier
by rinceWind (Monsignor) on Aug 06, 2006 at 22:36 UTC | |
by Aristotle (Chancellor) on Aug 07, 2006 at 09:22 UTC | |
by jhourcle (Prior) on Aug 07, 2006 at 14:19 UTC | |
by tye (Sage) on Aug 07, 2006 at 17:38 UTC | |
|
Re: Dominus on the non-greedy version of the ? quantifier
by tilly (Archbishop) on Aug 09, 2006 at 00:57 UTC | |
by Aristotle (Chancellor) on Sep 08, 2006 at 12:16 UTC |