lua-users home
lua-l archive

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


2012/8/20 Egor Skriptunoff <egor.skriptunoff@gmail.com>:
> Lua manual says:
>>  For this function, a caret '^' at the start of a pattern
>> does not work as an anchor, as this would prevent
>> the iteration.
>
> Amazingly, $ still works as an anchor!
> Why is it so asymmetric?

Because the string is processed left-to-right.  That introduces
a fundamental asymmetry.

> Does $ prevent the iteration, therefore must be disabled also?

No. $ simply says that a match of only part of the string is
not good enough.

> It is funny that one can get more than 1 match
> with $-anchored pattern:
> for a in ('Lua'):gmatch'.*$' do print(a) end
> for a in ('Lua'):gmatch'().*$' do print(a) end

The empty string matches ".*".  You need ".+" to prevent that.
(I have lost count of how many times I have spent 30
minutes on debugging because I forgot this.)