How to use gsub as this?

Hi,
I need to replace , by ; but only if it is in () and IDK how many () will be there. How to do it?

One question, do you need (,) to be replaced with ; or (;)

Ok, so i will give example, i need (,),(),(,) to be replaced by (;),(),(;)

That’s super simple then and doesn’t need much thinking.

Just do

local str = the string

string.gsub(str, "(,)", "(;)")

But problem is, that it can be also (....,77,1),(something,something), so i think, that i will need to use patterns, but idk how.

If you don’t need a special case for nested parentheses, this will do it

local s = "(,),(),(,),(....,77,1),(something,something)"
s = s:gsub("%b()", function(x) return x:gsub(",", ";") end)
print(s)

(;),(),(;),(....;77;1),(something;something)

2 Likes
string.gsub(str, "%(,%)", "(;)")

Would this work?