这是我的代码,
String xyz = "{\"status\":\"ok\",\"data\":[{\"RatingCount\":4}], [{\"RatingCount\":1}], [{\"RatingCount\":1}]\"code\":1}";
String pattern = ".*],\\s*\\[.*";//"(.*)(],\\s.*\\[)(.*)";
Pattern p1 = Pattern.compile(pattern);
Matcher m1 = p1.matcher(xyz);
boolean b = m1.matches();
System.out.println(b);
我想将模式'], ['
替换为""
。
我使用了replaceAll但没有运气
答案 0 :(得分:0)
答案 1 :(得分:0)
答案 2 :(得分:0)
此块的输出为:{"status":"ok","data":[{"RatingCount":4}{"RatingCount":1}{"RatingCount":1}]"code":1}
public static void main(String[] args) {
String str = "{\"status\":\"ok\",\"data\":[{\"RatingCount\":4}], [{\"RatingCount\":1}], [{\"RatingCount\":1}]\"code\":1}";
System.out.println(replace(str, "\\],\\s+\\["));
}
public static String replace(String str, String regex) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
return matcher.replaceAll("");
}