我可以删除在另一个角色同意后立即出现的每个角色实例吗?

时间:2017-08-31 15:39:26

标签: java regex string stringbuilder

customer2^sc1^admin1|server1~, customer3^sc1^admin1|server3, server2~, customer1^sc1^admin1|server1, server2, server3~

例如,我可以在,_的每个实例后删除每个~吗?我怎么能做到这一点?

1 个答案:

答案 0 :(得分:3)

您可以使用java String replaceAll fonction:

yourString = "customer2^sc1^admin1|server1~, customer3^sc1^admin1|server3, server2~, customer1^sc1^admin1|server1, server2, server3~"
yourString = yourString.replaceAll("~, ", "~")