Gsub not replacing characters

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    i want to convert a string to be used by gsub

  2. What is the issue? Include screenshots / videos if possible!
    the string doenst convert or recognize

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    rewriting the script, using letters and numers, smaller strings seem to work

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

repl={
	["%%"] = "%%%.",
	["%$"] = "%%%$",
	["%^"] = "%%%^",
	["%*"] = "%%%*",
	["%("] = "%%%(",
	["%)"] = "%%%)",
	["%."] = "%%%.",
	["%]"] = "%%%]",
	["%["] = "%%%[",
	["%+"] = "%%%+",
	["%-"] = "%%%-",
	["%?"] = "%%%?",
}
line = "'/'sfbre12344141'"
line = string.gsub(line,".",repl)
print(line) -- prints '/'sfbre12344141 instead of '%/'sfbre1234414


You don’t have a key for forward slash in your table Lol. You also don’t need to escape the replacement string since it’s not a string pattern.

local repl={
	["%"] = "%%",
	["$"] = "%$",
	["^"] = "%^",
	["*"] = "%*",
	["("] = "%(",
	[")"] = "%)",
	["."] = "%.",
	["]"] = "%]",
	["["] = "%[",
	["+"] = "%+",
	["-"] = "%-",
	["?"] = "%?",
	["/"] = "%/"
}
local line = "'/'sfbre12344141'"
line = string.gsub(line,".",repl)
print(line) --> '%/'sfbre12344141'