[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Possible pattern bug
- From: Coda Highland <chighland@...>
- Date: Sat, 16 Nov 2013 13:26:09 -0800
On Sat, Nov 16, 2013 at 1:20 PM, Michael Savage <firstname.lastname@example.org> 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?
> 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
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.