【发布时间】:2013-06-28 17:43:47
【问题描述】:
我有一个例子:
"hello . world . thanks ."
我想得到这个:
"hello. world. thanks."
我试过了
text = text.replaceAll(" .",".");
text = text.replaceAll(" \\.",".");
text = text.replaceAll(" \\.","\\.");
但它不起作用。有什么解决办法吗??
谢谢大家
【问题讨论】:
-
你尝试后得到了什么?
-
请注意,正则表达式中的
[.](仅包含句点的字符类)消除了.的通配符含义,而无需“转义”。此外,替换值不被视为正则表达式(而是has other rules)。 -
你的第二行适合我:
"hello . world . thanks .".replaceAll(" \\.", ".");