[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Filtering chars from string
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 27 Aug 2019 11:17:28 -0300
> (And yes always putting in the escaping '%' works fine and is probably
> safer/simpler than a bunch of special cases if you're generating the set…)
You can safely escape any non-alphanumeric character. Escaping
some alphanumeric characters changes their meanings.
> string.gsub("abc", "[a]", print);
a
> string.gsub("abc", "[%a]", print);
a
b
c
The following line should do the trick:
s = string.gsub(s, "%W", "%%%0")
-- Roberto