lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sat, Nov 16, 2013 at 1:20 PM, Michael Savage <mikejsavage@gmail.com> wrote:
> ( "[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?

That's correct.

> I think this is at least counterintuitive.

It's not so much that the behavior is counterintuitive as it is that
human pattern matching is TOO intuitive. The most important thing to
remember about regular expressions is that they always match
left-to-right.

Liam Devine's message beat me to the punch on showing how to sidestep
the behavior -- using a greedy quantifier before your pattern allows
the anchor point to be as far to the right as possible.

/s/ Adam