lua-users home
lua-l archive

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


>>>>> "Russell" == Russell Haley <russ.haley@gmail.com> writes:

 Russell> Ugh, I'm so intellectually lazy I had to read your answers.
 Russell> (rolling of eyes at myself). This is where I was going with it
 Russell> last night but couldn't figure it out. I agree with Martin
 Russell> that it's not very pretty.

This is the LPeg version, though it's stricter about following the
actual CSV spec than the solutions above:

  local re = require 're'

  local csv_sub_re = re.compile [[
  file       <- {~ record (%nl record)* (%nl / !.) ~}
  record     <- field ((',' -> '~') field)*
  field      <- escaped / nonescaped
  nonescaped <- [^,"%nl]*
  escaped    <- '"' ([^"] / '""' )* '"'
  ]]

  newdata = csv_sub_re:match(data)

-- 
Andrew.