How do you find the last occurrence of the template using string.find?
2 answers
local str = "123456AAA7890AAABBBB"
local s, e = str:find("A[^A]*$")
print(s)
print(str:sub(s))
Alternatively reverse the line and use a simpler call string.find
.
local str = "123456AAA7890AAABBBB"
local revstr = str:reverse()
local ind = revstr:find("A")
print(#revstr - ind + 1)
print(str:sub(#revstr - ind + 1))
+3
source to share