空格之间带负号的模式匹配

Pattern matching with minus sign between spaces

我有一个变量 message,它是从用户输入中获得的。例如:

!word number word-word---word

!word wordword-word

目前我创建了一个 table 并用每个 word/number 填充它(没有像 - 这样的数字)

--input table
it = {}
--put input in table
for _input in string.gmatch((message), '%w+') do
    it[#it+1] = { input=_input }
end

首先,我无法将它们之间带有减号的单词输入 table。 我也无法检查 it[2].input 是否不为空。这是我如何检查 table:

的示例
--TEST START
if it[1].input == 'test' then
    --do something
end
--TEST END

我试过 this 没有任何效果。

-- %s = space character
-- %- = escaped magic character
message = "!word number word-word---word"
-- might not be the most ideal method to fil an array up...
it = {(function() local t = {}; for _input in string.gmatch(message,"[^%s%-]+") do t[#t+1] = {input = _input} end return unpack(t) end)()}
print(t[2].input) --> number
--
--
it = {}
for _input in string.gmatch(message,"[^%s%-]+") do
    it[#it+1] = {input = _input}
end
-- now checking value should work fine
if (it[2] and it[2].input == "number") then -- checking that it[2] is set as something and then comparing input
   print("t[2].input = \"number\"");
end