You can also do this in the “old fashioned” way, i.e. without built-in pattern matching:
function parse(s,target)
local line = ''
local quote
for c = 1,
c = s:sub(c,c)
if c == quote then
quote = nil
elseif quote == nil and (c == '"' or c == "'") then
quote = c
end
if quote or c ~= target then
line = line .. c
else
print(line)
line = ''
end
end
print(line)
end
local s = [[item1;item2 "x;y;z";item3 args='arg1;arg2;arg3';item4]]
parse(s,';')
source
share