我不是正则表达式的专家。假设我有这个字符串:
String str = "0,tcp,1.00,0.00,0.11,0.00,0.00,0.00,0.00,1.00,normal."
如果我想删除,normal
并将其替换为点,则字符串将变为如下所示:
String str = "0,tcp,1.00,0.00,0.11,0.00,0.00,0.00,0.00,1.00."
我怎样才能在正则表达式中这样做?
非常感谢。
答案 0 :(得分:0)
您可以使用,\\w+\\.$
这样的正则表达式,其匹配任何以String
结尾的,
,然后.
和String.replaceAll(String, String)
String str = "0,tcp,1.00,0.00,0.11,0.00,0.00,0.00,0.00,1.00,normal."
.replaceAll(",\\w+\\.$", "\\.");
System.out.println(str);
输出(按要求)
0,tcp,1.00,0.00,0.11,0.00,0.00,0.00,0.00,1.00.