(“Attempt to update a read%-only table %s.”):format(tableName)
This pattern is going to be used in a regex search using string.find. “-” is a magical character in regex so I escaped it with “%” . My problem is the format function reads “%-” as a formatting directive despite not being one. I’m aware I can break the string in two and solve this particular problem, but as a general question: Is it possible to escape magic characters and format a regex pattern at the same time?
As string.format is first formatted then the string pattern, you can escape them with %% to format them as a literal %, e.g. %%- would be formatted as %- then that’ll be the string pattern to match.
@blockzez answer is good for what your looking for If I understand correctly what your trying to achieve.
I just want to add on and clarify that you are referring roblox/Lua, this is not regex at all, but rather lua’s own string pattern framework. This should not be referred to as “RegEx” as this causes confusion.