[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LPeg Matching Inverse of Set
- From: Mitchell <lists@...>
- Date: Wed, 9 Mar 2022 11:29:57 -0500
Hi,
On Wed, 9 Mar 2022 15:17:39 +0000
Scott Morgan <blumf@blueyonder.co.uk> wrote:
> I'm starting out with LPeg but struggling with inverse matching on a set.
>
> As an example, trying to match a substring without ';' or ',' chars
>
> patt = (-lpeg.S";,") ^ 1
>
> Fails with "loop body may accept empty string"
>
> Plain -lpeg.S";," does the right thing for the first char, so why
> doesn't ^ 1 extend that for longer strings?
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.
Cheers,
Mitchell