Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all chars from a string except "a","b","c","d"

I have a string where I want to replace all chars and digits with "", except chars a,b,c, d.

Instead of having to write multiple lines of long code like in the example below, is there some other way to write this more efficient?

myString:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$%,]", "") --special chars
... --same for chars
... --same for digits
like image 467
Richard Avalos Avatar asked Dec 05 '25 02:12

Richard Avalos


1 Answers

Use caret symbol ^ That is, [^abcd]

Caret symbol negates your set.

E.g., you can read it more carefully here.

like image 127
Vyacheslav Avatar answered Dec 06 '25 17:12

Vyacheslav