输入
String s1 = "This Payer Ref [customerRef] does not exist/This Card Ref [cardRef] has already been used."
我想删除所有带有[variable]的部分
输出
"This Payer Ref does not exist/This Card Ref has already been used."
请注意,给定字符串中可以有 n 个[variable]
。
我尝试了很多方法,但没有成功。
最佳答案
你可以使用这个。
String s1 = "This Payer Ref [customerRef] does not exist/This Card Ref [cardRef] has already been used.";
s1=s1.replaceAll("\\[\\w+\\]", "");
System.out.println(s1);
关于Java 字符串拆分/删除 n 个特殊字符部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58949016/