What do you want to achieve?
I need to start finding patterns from the end using string.find in the most optimized way possible.
What is the issue?
I can’t think of a way of doing so.
What solutions have you tried so far?
I’ve tried looping over all the characters from the beginning however this simply wasn’t efficient enough because the strings I use are very large. Maybe there’s a way to loop from the end?
This is pretty much what I’m trying to achieve. Note that the character I’m looking for isn’t always second to last.
local example = "qasfjmnbz"
local pattern = "b"
print(string.find(example, pattern))
In the output I want it to return 8 8.
Thanks for the response!
Here is the code, if you want to understand more on what it does, please visit and read the link that @pumpkyrofl replied.
local example = "qasfjmnbz"
local pattern = "b"
local regexCrafted = string.format("%s[^/]*$", pattern)
local foundAt = string.find(example, regexCrafted)
print(foundAt)
Basically, you will start searching from the end of the string with the specific pattern. If found, return the index where it is found, otherwise, return nil.