So what i want to make is a function that changes <a>...</a> with something. I have the base of the function, the only thing i wanna know is how to get the string before s and after s[where s is the gmatch output]
local str = ThatThing("Hello<a>exclamation_mark</a> How are you<a>question_mark</a>")
print(str) --> Hello! How are you?
What I have right now is
for s in value:gmatch('{'..base..'}(.*){/'..base..'}') do
end
Nevermind, found a way to do it with gsub, also noone responds
[gsub version works better]
local pack = {['happy']=':)',['sad']=':('} --> change Indexes and Values to your liking
local output = 'Happy face --> {smile}happy{/smile} ... Sad face --> {smile}sad{/smile}' --> Variable
for index,connect in pack do
output = output:gsub('{smile}'..index..'{/smile}',connect) --> smile is variable too
end
print(output) --> "Happy face --> :) ... Sad face --> :("
FYI you can do it in a single pass: gsub will accept a table where you can tell it about what to do with capture groups:
local pack = {['happy']=':)',['sad']=':('} --> change Indexes and Values to your liking
local output = 'Happy face --> {smile}happy{/smile} ... Sad face --> {smile}sad{/smile}' --> Variable
output = output:gsub('{smile}(.-){/smile}', pack)
print(output) --> "Happy face --> :) ... Sad face --> :("
You can also give it a function that accepts as its argument the capture, if you want to do fancier things.