[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Possible pattern bug
- From: Michael Savage <mikejsavage@...>
- Date: Sat, 16 Nov 2013 21:20:59 +0000
( "[a] [b] c" ):match( "(.-)%] c" )
-> "[a] [b"
The shortest possible match is now "". I guess in this case it's the
first character it sees anchoring the match?
I think this is at least counterintuitive.
Mike
On Sat, Nov 16, 2013 at 01:06:27PM -0800, Coda Highland wrote:
> No, it's not a bug -- the initial %[ is still greedy. It wants to
> capture the first [ it finds. The subsequent non-greedy .- then
> captures the fewest possible characters that still satisfies a match
> in its position -- but that position has already been determined by
> the pattern leading up to it.
>
> /s/ Adam
>
> On Sat, Nov 16, 2013 at 12:59 PM, Michael Savage <mikejsavage@gmail.com> wrote:
> > Hi lua-l,
> >
> > ( "[a] [b] c" ):match( "%[(.-)%] c" )
> > -> "a] [b"
> >
> > >From http://www.lua.org/manual/5.1/manual.html#5.4.1 or
> > http://www.lua.org/manual/5.2/manual.html#6.4.1:
> >
> >> a single character class followed by '-', which also matches 0 or more
> >> repetitions of characters in the class. Unlike '*', these repetition
> >> items will always match the shortest possible sequence;
> >
> > The shortest possible sequence for the above is "b". Is this a bug?
> >
> > Mike
> >
>