要删除所有非字母数字字符,正则表达式应为
x = regexp_replace(somestring, '[^a-zA-Z0-9]+', '', 'g')
但是如果我想保留下划线怎么办?
a-zA-Z0-9_
\w
[^\w]+
\W+
那么您需要使用:
x = regexp_replace(somestring, '\W+', '', 'g')
\W的意思和[^a-zA-Z0-9_]相同。
\W
[^a-zA-Z0-9_]
a-zA-Z0-9_
相当于\w
。这样更容易阅读。 - Loamhoof[^\w]+
等同于\W+
。 - speakr