✓ Accepted answer
Namaste it is, dual
First of all, you have to realise 1 thing - string.match() does NOT return 2, 3, 4 or n things. It returns 1 thing. One. This can be found here:
https://developer.roblox.com/api-reference/lua-docs/string.
"If a match is found, it is returned"
Next, you should use an i,v pair loop. What you're doing now is more efficient than said loop, so yes it's more optimised, however it's evident you don't need this optimisation more than you need readability. I recommend rewriting this loop with an i,v pair loop.
Second, can you give an example of the array's values? Right now I'm using {"dlp | 1", "sin | 2", "viking | 3"}, and my code works with this.
I would also like to mention your pattern has a lot of redundant things, that you're also using wrong. lol(?).
I recommend reading more about Lua RegEx/pattern matching on:
http://lua-users.org/wiki/PatternsTutorial
Here is some reformatted code I wrote.
local arr = {"dlp | 1", "sin | 2", "viking | 3"}
for _, v in pairs(arr) do
local match_name = "(%a+)"
local match_number = "(%d)"
local matched_name, matched_number = string.match(v, match_name), string.match(v, match_number)
print(matched_name, matched_number)
end
That is all
2 comments
try reversing the order u put the statsData[i] and pattern in the string.match()
Use string.find