[ create a new paste ] login | about

Link: http://codepad.org/Yawzh009    [ raw code | output | fork ]

Lua, pasted on Mar 12:
local function tokenize(param)
        local tokens = {};
        local function getmatch(match)
                table.insert(tokens, match);
                return '';
        end
        local old = param;
        while param and param ~= '' do
                if param:match'^"' then
                        param = string.gsub(param, '^"([^"]*)"%s*', getmatch);
                else
                        param = string.gsub(param, '^([^%s"]+)%s*', getmatch);
                end
                if param == old then
                        getmatch(param);
                        break;
                end
                old = param;
        end
        return tokens;
end

for _, t in ipairs(tokenize([["hi there" "what there" 3 003 "bob's your uncle" bye!]])) do print(t); end


Output:
1
2
3
4
5
6
hi there
what there
3
003
bob's your uncle
bye!


Create a new paste based on this one


Comments: