Originally Posted by Sharlikran
Q1) Did I do it right?
Q2) Why does 3 work in all cases. I tried a 2 for the first example with only v1, and v2 and I got a number and a string.
|
If it works, you did it right
Lua Code:
select(3, string.find(name, pattern))
-- or if you use colon syntax
select(3, (name):find(pattern))
This works because string.find(...) returns starting and ending position of the pattern in the string and then captures that you have enclosed in brackets. If pattern is not found, return value is nil.
Lua Code:
texture = art/maps/glenumbra/daggerfall_base_0.dds
pattern = "([%w%-]+)/([%w%-]+_[%w%-]+)"
string.find(texture, pattern)
--or colon syntax:
(texture):find(pattern)
--returns: 5, 34, "glenumbra", "daggerfall_base"
Pattern "(maps/)([%w%-]+)/([%w%-]+_[%w%-]+)" has one more closure, so thats why I have used select(4,...).