You don't need LPeg for that, gsub does it nicely if the format is fixed: s = io.read"*a" io.write(s:gsub("%[(.-)%].-{(.-),%s*(.-)}",function (i,a,b) return string.format("[%s] = {%s, %s}",i+10,b,a) end)