So I wrote a
strip function like python, where it removes leading and trailing whitespaces, as well as the optional chars argument.
function string_ext.strip(s, chars) -- Strips leading and trailing whitespace, as well as characters specified by the chars string return (s:gsub("^%s+", ""):gsub("%s+$", ""):gsub(chars and string.format("[%s]", chars) or "", "")) end
It works perfect, but I don’t like how I have chained
gsub calls. I feel like I could do it in one call, but am unsure of a pattern to use.