I want to replace matched string with some function.
I've used '%1' to find strings, but I couldn't use the matched strings.
print(text) showed me %1, not matched string.
original_text = "Replace ${test01} and ${test02}"
function replace_function(text)
-- Matched texts are "test01" and "test02"
-- But 'text' was "%1", not "test01" and "test02"
local result_text = ""
if(text == "test01") then
result_text = "a"
elseif(text == "test02") then
result_text = "b"
end
return result_text
end
replaced_text = original_text:gsub("${(.-)}", replace_function("%1"))
-- Replace result was "Replace and"
-- But I want to replace "Replace ${test01} and ${test02}" to "Replace a and b"
print(replaced_text)
How can I use matched string in gsub?