silverbullet icon indicating copy to clipboard operation
silverbullet copied to clipboard

Lua: Pattern group matching variables not expanded in string functions

Open mjf opened this issue 10 months ago • 1 comments

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

mjf avatar Feb 28 '25 13:02 mjf

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.

dklawren avatar Apr 05 '25 20:04 dklawren