The following regexes show me static analyzer warnings, but they’re functioning exactly as intended (both on roblox & on Lua: demo).
- “([&$%%].)”: capture an &, $, or % followed by any character.
- “(%%%d*%.?%d*)([a-zA-Z%%])”: capture a C-style “printf” specifier.
- “[%%]”: minimal capture string which causes this issue.
You can reproduce by creating a new place, throwing a script in the workspace & pasting these contents into it:
lua script
local secretDecoderRing = {
["&0"] = "foo";
["%1"] = "bar";
["$2"] = "baz";
--etc.
};
local text = "&0 then %1 then $2";
print((string.gsub(text, "([&$%%].)", function(c) return secretDecoderRing[c]; end)));
--> foo then bar then baz
local text = "Hello from %30.4s"
for style, formatType in string.gmatch(text, "(%d*%.?%d*)([a-zA-Z])") do
print(style, formatType);
end
-->%30.4 s