So this is what I want.
Input:
"("ok"), ("yes")" -- String
Output:
{"ok", "yes"} -- Table
How would I pull this off.
So this is what I want.
Input:
"("ok"), ("yes")" -- String
Output:
{"ok", "yes"} -- Table
How would I pull this off.
Some crazy idea of mine is to use string.gmatch to extract only the alphanumeric characters of the string then append those to a table:
local input = "(\"yes\"), (\"ok2\")"
local new = {}
for i in string.gmatch(input, "(%w+)") do
table.insert(new, i)
end
print(new)
I am positive there is some other method of doing this but I currently can’t think of it.
Might be overcomplicating it too with an iterator.
Then again, remember this ignores EVERYTHING except for alphanumeric characters so use another string pattern if you want to be DEAD specific (I’ll try to come up with one).
apparently there is no split function in lua (for default) so match prob best option
local strings = "('ok'), ('yes')"
strings = strings:gsub("[()']", "")
local tables = strings:split(", ")
print(tables[1], tables[2]) --ok yes
local strings = "(\"ok\"), (\"yes\")"
strings = strings:gsub("[()\"]", "")
local tables = strings:split(", ")
print(tables[1], tables[2]) --ok yes
local strings = [[("ok"), ("yes")]]
strings = strings:gsub("%(\"([^,]+)\"%)", "%1")
local tables = strings:split(", ")
print(tables[1], tables[2]) --ok yes
Just let the user input JSON and parse it through using HttpService:JSONDecode
I tried that, it got very laggy.
I know this is closed but you can also use
function gmatches(s :string, pattern :string) :{string}
local matches = {}
for match in string.gmatch(s, pattern) do
table.insert(matches,match)
end
return matches
end
print(gmatches('(("test"),("hi"))','%("(.-)"%)'))
output
19:37:22.287 ▼ {
[1] = "test",
[2] = "hi"
} - Edit