How to only separate words outside of quotes?

Hello there! I’m working on my own admin command panel, and I’m trying to make kick and ban commands with reasons, however, my script separates every single word and puts them into a table, and then runs the commands with the arguments inside the table, what I’m trying to do is to not separate words that are inside of quotation marks, like this:
Message: :kick Player1 "I would like to ask you to get out of the game." Table: {':kick', 'Player1', '"I would like to ask you to get out of the game."'}
Here’s the part of the script that separates the words:

local cmd = string.split(msg, " ")
local cmd1 = cmd[1]
local arg1 = cmd[2]
local arg2 = cmd[3]
--// Runs command
if cmds[cmd1] then
	cmds[cmd1](arg1, arg2)
else
	warn("This command does not exist.")
end

It works perfectly fine for things that don’t use whole words, only arguments. Can someone help me with this? Thanks!

I’m assuming you know what order the arguments should come in, so you can do something like:

local matchString = ':(.+)%s(.+)%s(%b"")' 
local command, name, reason = string.match(':kick Noob "Being a dummy"', matchString) 
print(command,name,reason) -- command: kick, name: Noob, reason: "Being a dummy"

If you don’t want the quotes around the text, you can trim it:

reason = reason:sub(2, reason:len() - 1)
1 Like

Alright, I’ll try it later, tho I think it should work, so thanks!

1 Like