![](/img/trans.png)
[英]Java regular expression to remove all non alphanumeric characters EXCEPT spaces
[英]Regular expression to remove all non-alphanumeric characters except $
正则表达式的新手。 我希望能够删除$以外的所有非字母数字字符。
因此,对于像“我今天在这里今天”这样的字符串,结果应该是“我今天在这里今天”
我已经尝试过了,没有运气。
[^a-zA-Z\\s$] and [$^a-zA-Z\\s] and [^a-zA-Z$\\s]
String regex = "[^a-zA-Z\\s$]";
String string = "I am here $today#";
string = string.replaceAll(regex, "");
System.out.println(string); // I am here $today
这很好用...
使用以下方法可能会有所帮助:
replaceAll("[^\\w\\s\\$]", "");
\\ w是[a-zA-Z_0-9]的缩写
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.