lua-users home
lua-l archive

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


On 09/03/2022 16:29, Mitchell wrote:
> Hi,
> 
> On Wed, 9 Mar 2022 15:17:39 +0000
> Scott Morgan <blumf@blueyonder.co.uk> wrote:
> 
>>   patt = (-lpeg.S";,") ^ 1
>>
>> Fails with "loop body may accept empty string"
>>
> 
> Try this: (1 - lpeg.S";,")^1
> 
> It matches any one character minus those in the set, one or more times. A '-patt' by itself consumes no input, so it can match an empty string, and LPeg doesn't allow that for loops.
> 

That seems to work, thanks.

  patt = (1 - lpeg.S";,") ^ 1
  patt:match"abc;"
4
  patt:match";abc"
nil

I think I'm making sense of it now, wasn't properly understanding how
the - operator was working there. Re-reading the docs, I see where I
went wrong.

Scott