lua-users home
lua-l archive

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

On Jun 28, 2012, at 17:35, Daurnimator <> wrote:

> On 29 June 2012 08:07, Geoff Leyland <> wrote:
>> Hi,
>> When you're parsing csv files, it would be useful to look for the end of a field with the pattern "[,$]" so that you can find the end of the last field as well as the ends of the previous fields.  Trouble is, this doesn't seem to work.  Can anyone tell me what I'm missing?
>> (I looked at [1] and as far as I can tell, that code expects the last field to end with a comma)
>> Cheers,
>> Geoff
>> [1]
> Yes using $ or ^ in a class would be useful, but sadly not possible.
> You can however use the frontier pattern, it'll match the start or end
> of a string as a null byte.
> So you can use %f[,%z]
> See the 5.2 manual for more info.

The frontier pattern doesn't help if you need to escape inner quotes. Like:

" test ""this is cool!"""

Or it does and I'm not smart enough.

I looked at LPEG and even used the provided example, but it was no
match for Quickbooks exports. I couldn't find one that did work, but
if you want my CSV iterator, which I'm not claiming is awesome, let me

Andrew Starks