[prev in list] [next in list] [prev in thread] [next in thread]
List: lua-l
Subject: Re: Anchors in string.gmatch()
From: Dirk Laurie <dirk.laurie () gmail ! com>
Date: 2012-08-20 3:47:48
Message-ID: CABcj=tk5sU_86hH3qFVtabMQ7hZ+hCsYZA-PDU+qhBGZb9uZuw () mail ! gmail ! com
[Download RAW message or body]
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.)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic