[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: possible doc/behavior error of patterns
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 22 Nov 2019 10:00:41 -0300
> ```
> hippi@vas:~$ lua5.3
> Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio
> > print(('aaa x bbb'):match'(.-) x (.*)')
> aaa bbb
> ```
> (lj 2.0.5 does this as well)
>
> i would expect that the 1st capture should be empty without a `^` at
> the beginning of the pattern, as the manuals (up to lua 5.4) say:
> "a single character class followed by '-', which also matches zero or
> more repetitions of characters in the class. Unlike '*', these
> repetition items will always match the shortest possible sequence;"
string.match looks for the *first* match. The resulting match starts
at position 1, while a match with an empty capture (no 'a's) starts at
position 4; therefore it is not the first one.
-- Roberto