lua-users home
lua-l archive

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


On Tue, Aug 27, 2019 at 5:55 AM Scott Morgan <blumf@blueyonder.co.uk> wrote:
>
> What's the best way to filter out non-specified chars from an ASCII
> string? (so no need to worry about UTF8, etc.)
>
> local allowed = "AbC"
> local txt = "dDcCbBaA"
>
> filter(txt, allowed, "") -- ret: "CbA"
> filter(txt, allowed, "?") -- ret: "???Cb??A"

function filter(t,a,r)
   print((t:gsub("[^"..a.."]",r)))
end