Answered by
5 years ago Edited 5 years ago
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.
1 | local arr = { "dlp | 1" , "sin | 2" , "viking | 3" } |
3 | for _, v in pairs (arr) do |
4 | local match_name = "(%a+)" |
5 | local match_number = "(%d)" |
6 | local matched_name, matched_number = string.match(v, match_name), string.match(v, match_number) |
7 | print (matched_name, matched_number) |
That is all