local s = "/path?first,,,second,,,third,value,,,fourth" s = s:gsub("^[^?]*%?", ""):gsub(",,,", "\0") for word in string.gmatch(s, "[^\0]+") do print(word) end