lua-users home
lua-l archive

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

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"

For extra difficulty, plain Lua 5.1, no modules (lpeg, etc.)

I can see a way using gsub(txt, ".", filter_func), but was wondering if
there are any tricks that might make it simpler.