lua-users home
lua-l archive

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


On 27/08/2019 10:44, Luiz Henrique de Figueiredo wrote:
> 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
> 

Doh! Knew I was missing something simple, hence the question.

Is there a limit to how big those sets can be? In practice I'd be
looking at a few dozen allowed chars.

Scott