silverbullet
silverbullet copied to clipboard
Lua: Pattern group matching variables not expanded in string functions
I found out the following one:
```space-lua
function toSnakeCase(text)
text = string.gsub(text, "([a-z])([A-Z])", "%1_%2")
return string.lower(text)
end
```
called as:
${toSnakeCase('CamelCase')}
yields:
came%1_%2ase
but subgroup matching variables not expanded. Expected:
camel_case
I think this is related to an issue I am having as well trying to write a function to url escape a string.
local function url_escape(str)
return string.gsub(str, "([^%w%. %-])", function(c)
return string.format("%%%02X", string.byte(c))
end)
end
called as:
print(url_escape("#Inbox"))
Should give %23Inbox but this is not working in space-lua and just returns the original string #Inbox.