lua-users home
lua-l archive

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


On 27 July 2015 at 03:40, Daurnimator <quae@daurnimator.com> wrote:
> I want to ensure that a string always ends in a single "/".
> If it has more than one, the extras should be removed
> If it has none, a "/" should be appended.
>
> "/*$" should match all the '/' at the end of the string, and replace
> them with a single "/".
> I got an unexpected result:
>
>     > ("d//"):gsub("/*$", "/")
>     d// 2

FWIW because of this my approach for this (e.g. in path/URL
normalization) is generally s:gsub("/+$", "").."/"

Regards,
Matthew