lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 19 August 2015 at 21:18, Soni L. <fakedme@gmail.com> wrote:
> Are there any use-cases for string.gsub(str, "().", "%1")?
>
> If not, can it please become an error? It's just... weird... unexpected...
>
> (I'm talking about the very weird number to string coercion which happens
> there)

I wanted to triumphantly say there was a use-case, in converting text
to netstrings. However unfortunately the result is always off-by-one:

  ("hello world!"):gsub("^(.*)()$", "%2:%1,") -- 13:hello world!,

See https://en.wikipedia.org/wiki/Netstring

However in any case I don't think the fact that position captures can
be used directly as replacements is really an issue, it's pretty much
exactly what I would expect to happen.

Regards,
Matthew