lua-users home
lua-l archive

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


Hey Sean,

This is great and works wonderfully, Thank you!

Regard,

Dan

On Mar 22, 2013 7:54 PM, "Sean Conner" <sean@conman.org> wrote:
It was thus said that the Great dan young once stated:
> Hello all,
>
> FIrst of all Lua is awesome!  I'm a fairly newbie @ Lua and a total newbie
> @ LPeg.
>
> I'm trying to figure out how to do the following. FOr example, I have the
> following strings, and I only want to match strings a and e.
>
> a = 'disease_show/881/////'
> b = 'disease_show/266/tests///'
> c = 'disease_show/191/description////'
> d = 'disease_show//description////'
> e = 'disease_show/881/'
>
>
> I don't know how to exclude anything that might have letters after the
> digits and the slash (i.e... b and c)
>
> disease_match = (P'disease_show/'*R'09'^1*P'/'^0)
>
> > = disease_match:match(a)
> 22
> > return  disease_match:match(b)
> 18
> > return  disease_match:match(c)
> 18
> > return  disease_match:match(d)
> nil
> > return  disease_match:match(e)
> 18

  Lines a, b, c, and e match the pattern given.  What LPeg is returning is
the first position that doesn't match in the string (this is so the rest can
be passed on to other patterns).  What I think you want is:

        disease_match = (P'disease_show/'*R'09'^1*P'/'^0 * -P(1))

That final "-P(1)" matches the end of the string (i.e. there is no more
input to match).

  -spc (Hope this helps)