lua-users home
lua-l archive

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


Okay, that's excellent! Thanks for both responses. I was running into troubles, because I've been trying to do something slightly more complicated.

print(p:match('*ab***cd**,*This**is**a***sentence,***ijk**lm******'))

So, I want to separate the comma separated tokens, trim the left and right whitespace, and preserve the white space in the middle.

Any ideas?

Thanks.

Josh

Jose Luis Hidalgo wrote:
ws = lpeg.P('*')
sep = lpeg.P(',')
elem = ws^0 * (lpeg.C( (1 - (sep+ws) )^0)) * ws^0
p = elem * (sep * elem)^0

2007/4/12, Joshua Jensen <jjensen@workspacewhiz.com>:
As my first attempt at using LPeg, I took the Splitting a String example
and wanted to extend it to filter out whitespace on either side of the
string.  All whitespace (represented as a visible *) is removed from the
pattern below except the whitespace at the end.  I understand why it
doesn't work; I don't understand how to make an elegant fix for it.  I
tried all kinds of approaches without success.