Chat command parsing with patterns

I’m having some problems with this, everything else works, but parsing quotes like Source does is killing me.
I know I could do this just by using player:ConCommand but I prefer doing stuff from scratch.

This is what I have
[lua]
local str = ‘!this is “random shite” and “another arg”’

local cmd = str:gsub( “^!/(.)", “%1” ) – this
str = str:gsub( "^!/%s
”, “” ) – is a test “random shite”

local args = {}

for v in str:gmatch( “(%S+)” ) do
table.insert( args, v )
end

–[[
args:
is
“random
shite”
and
“another
arg”
]]
[/lua]

And this is what I want the args to be:



is
"random shite"
and
"another arg"


Could someone help me?

Options:
If you’re willing to use LPeg:

Or there’s this, by Lexi:
[lua]local text = ‘“this” is some "text which"has quoted “sections in” it’
local quote = text:sub(1,1) ~= ‘"’
local ret = {}
for chunk in string.gmatch(text, ‘[^"]+’) do
quote = not quote
if quote then
table.insert(ret,chunk)
else
for chunk in string.gmatch(chunk, “%a+”) do
table.insert(ret,chunk)
end
end
end
for k,v in ipairs(ret) do
print(k,v)
end
[/lua]

Enjoy!

Thanks, have a heart :buddy:

Hey I was going to post that! :argh: