【发布时间】:2017-05-21 04:14:11
【问题描述】:
我有一个类似23.Piano+trompet 的字符串,我想使用这个函数从字符串中删除23. 部分:
private String removeSignsFromName(String name) {
name = name.replaceAll(" ", "");
name = name.replaceAll(".", "");
return name.replaceAll("\\^([0-9]+)", "");
}
但它不这样做。另外,运行时没有错误。
【问题讨论】:
-
您转义了
^,因此它会搜索不存在的文字^。 -
.匹配任何字符,replaceAll()替换所有字符。转义点"\\."
标签: java regex string replaceall