Proposal for lpeg

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Proposal for lpeg

albertmcchan
to make re.anywhere more convenient, i added = prefix in re.lua for anywhere search
this produce very readable lpeg re pattern

t = 'this and that and whatever'

-- search for end position of that
= re.match(t, "= 'that'")
14

-- search for start and end of 'that'
= re.match(t, "=({} 'that' {})")
10      14

-- lua pattern ".*and(.*)"
= re.match(t, "(= 'and')+ {.*}")
 whatever
Reply | Threaded
Open this post in threaded view
|

Re: Proposal for lpeg

albertmcchan
On Feb 7, 2018, at 5:49 PM, albertmcchan <[hidden email]> wrote:

> to make re.anywhere more convenient, i added = prefix in re.lua for anywhere search
> this produce very readable lpeg re pattern
>
> t = 'this and that and whatever'
>
> -- search for end position of that
> = re.match(t, "= 'that'")
> 14
>
> -- search for start and end of 'that'
> = re.match(t, "=({} 'that' {})")
> 10      14
>
> -- lua pattern ".*and(.*)"
> = re.match(t, "(= 'and')+ {.*}")
> whatever

reply to myself, =name already have meaning, so above patch will fail lpeg test.lua

maybe using '>' instead for anywhere search ?