从"a","b","c","d"除去字符串中的所有字符

Ric*_*los 3 lua gsub lua-patterns

我有一个字符串,我想,以取代所有的字符和数字用"",除了字符a,b,c,d.

而不是像下面的例子中那样编写多行长代码,还有其他一些方法可以更有效地编写它吗?

myString:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$%,]", "") --special chars
... --same for chars
... --same for digits
Run Code Online (Sandbox Code Playgroud)

Vya*_*lav 7

使用插入符号^[^abcd]

插入符号否定了你的设置.

例如,你可以在这里仔细阅读.