I want to use string.find to get any string that is any 4 digits, then a space, and another 4 digits (example: "6969 6969"). I've tried "%d%d%d%d %d%d%d%d" and "%d%d%d%d%s%d%d%d%d" and also "%d%d%d%d".." ".."%d%d%d%d" and nothings worked. Someone please help, thanks.
✓ ANSWER ACCEPTED
Using string.find or string.match, how could I get these numbers?
1 answer
✓ Accepted answer
Try using string.match.
string.match will search through a string for a pattern (second argument), and return the first matching substring if one is found
http://robloxdev.com/articles/string-patterns-reference
Pattern you want:
"%d%d%d%d%s%d%d%d%d"
Example of how this works:
local pattern = "%d%d%d%d%s%d%d%d%d"
local string = "7394 1027"
local match = string.match(string,pattern)
print(match)
Output: 7394 1027
Your pattern was missing the whitespace character class, %s.
1 comment
0
Thanks!
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
use the string.sub function, example: if string.sub("6969 6969", 1, 5) == " 6969 " then --... end
@incapaz, that's not precisely what he is asking for.
an example for that specific string.
No, the string must return true if it matches with ANY 4 digits, a space, and then ANY 4 digits. "6969 6969" was the example.
String.find looks for the first match of patterns in string s. If a match is found, then String.find returns the locations (1, 3, etc.)