If you are using MySQL Version 8+ then below is the built-in function that might help you better.
MySQL Query:
SELECT REGEXP_REPLACE('w"w\'w. ex%a&m:p l–e.c)o(m', '[("\'%[:blank:]]&:–)]', '');
Almost for all bugging characters-
SELECT REGEXP_REPLACE(column, '[\("\'%[[:blank:]]&:–,#$@!;\\[\\]\)<>\?\*\^]+','')
MySQL built-in function (MySQL version 8+): REGEXP_REPLACE (string, patterns, replace-with)
REGEXP_REPLACE gives you the facility to search multiple characters and replace them in one shot.
To find multiple characters, pattern is:
[
( -- open parenthesis
" -- double quotes
\' -- single quotes
% -- percentage
[:blank:] -- space
& -- ampersand
: -- colon
– -- non ASCII character
) -- close parenthesis
]
Notice the [:blank:], this is a [:character_class:] and MySQL does support many names.
Character Class Name |
Meaning |
alnum |
Alphanumeric characters |
alpha |
Alphabetic characters |
blank |
Whitespace characters |
cntrl |
Control characters |
digit |
Digit characters |
graph |
Graphic characters |
lower |
Lowercase alphabetic characters |
print |
Graphic or space characters |
punct |
Punctuation characters |
space |
Space, tab, newline, and carriage return |
upper |
Uppercase alphabetic characters |
xdigit |
Hexadecimal digit characters |