Re: greedy/non-greedy regex assertions

2002-07-04 Thread Ashley Winters

On Thursday 04 July 2002 10:47 am, Larry Wall wrote:
 On Thu, 4 Jul 2002, Ashley Winters wrote:
 So I'd guess that we just don't talk about :-1, but rather say that

 *$min..$max

 is naturally greedy, and as with any quantifier you write

 *$min..$max?

 to get minimal matching.

I would expect /a*1..2?/ to mean /[a*1..2]?/ just looking at it. How can ? 
ever mean non-greedy unless it follows a metachar [*+?]?

 But sigh, it would fix so many novice bugs to make minimal matching
 the default...

I agree wholeheartedly. *sigh*

Ashley Winters




Re: greedy/non-greedy regex assertions

2002-07-04 Thread Ashley Winters

On Thursday 04 July 2002 11:07 am, Ashley Winters wrote:

 I would expect /a*1..2?/ to mean /[a*1..2]?/ just looking at it. How
 can ? ever mean non-greedy unless it follows a metachar [*+?]?

Perhaps I can respond to my own question. In /.+?/ . is an assertion, + is an 
assertion, and ? is a modifier. Therefore, it means /.1,Inf:m/ or 
something close, where :m is mnemonic for minimal.

Did apoc 5 ever say . means .?

Ashley Winters



Re: greedy/non-greedy regex assertions

2002-07-04 Thread Larry Wall

On Thu, 4 Jul 2002, Ashley Winters wrote:
: On Thursday 04 July 2002 10:47 am, Larry Wall wrote:
:  On Thu, 4 Jul 2002, Ashley Winters wrote:
:  So I'd guess that we just don't talk about :-1, but rather say that
: 
:  *$min..$max
: 
:  is naturally greedy, and as with any quantifier you write
: 
:  *$min..$max?
: 
:  to get minimal matching.
: 
: I would expect /a*1..2?/ to mean /[a*1..2]?/ just looking at it. How can ? 
: ever mean non-greedy unless it follows a metachar [*+?]?

Well, that's exactly how {1,2}? works in Perl 5, and {1,2} isn't a metacharacter.
It is, however, a quantifier.

In general, it makes no sense to put the quantifier ? after a zero-width
assertion.  It'd mean Check this assertion but I don't care if it matches.

:  But sigh, it would fix so many novice bugs to make minimal matching
:  the default...
: 
: I agree wholeheartedly. *sigh*

I wasn't seriously proposing it, of course, since it would instead
inspire a whole new set of novice bugs:

Gee, how come this:

my ($num) = /(\d*)/

always sets $num to zero?

We'll stick with greedy matching by default, and take our current
set of lumps...

Larry