[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Iterating over string with delimiter that is multiple occurrences of the same character
- From: Andrew Starks <andrew.starks@...>
- Date: Fri, 11 Oct 2013 09:28:34 -0500
On Fri, Oct 11, 2013 at 9:16 AM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> I think that single ";" need to be escaped, if I read the OP's request
>> correctly.
>
> You're right. I missed that part: "where a, b and c can be any length
> and can include non repeating occurrences of ;".
>
> This should work then:
> t = s..";;"
> for p in t:gmatch("(.-);;") do print(p) end
>
Also, I always feel compelled to offer the lpeg answer.
I'm sure this can be improved, as well:
lpeg = require'lpeg'
sep = lpeg.P";;"
item = sep * lpeg.Cc"" + lpeg.C(( lpeg.P(1) - sep )^1 ) * (sep + -1)
items = lpeg.Ct(item^1 )
t = items:match(s)
for i,v in ipairs(t) do
print(i, v)
end