求一正则匹配
String ss="{\"@type\":\"com.game.backpack.structs.Equip\",\"attributes\":[{\"state\":0,\"type\":13,\"value\":10},{\"state\":0,\"type\":11,\"value\":1},{\"state\":0,\"type\":15,\"value\":1},{\"state\":0,\"type\":16,\"value\":1}],\"automaticSellbind\":0,\"baptizeAttributes\":[],\"bind\":false,\"blessNum\":0,\"blessValue\":0,\"clearBlessNumDay\":16404,\"createTime\":1417322920,\"durability\":2147483647,\"equipBelongType\":2,\"equipInsure\":0,\"equipPos\":0,\"extendStr\":{\"@type\":\"java.util.HashMap\"},\"gradeNum\":0,\"gridId\":85,\"id\":5631562744724995728,\"itemCooldownMap\":{\"@type\":\"java.util.HashMap\"},\"itemModelId\":104080011,\"itemsShowTime\":0,\"jewels\":[],\"kingOil\":false,\"lost\":false,\"losttime\":0,\"num\":1,\"packageId\":0,\"parameters\":{\"@type\":\"java.util.HashMap\"},\"ringAttributes\":[],\"ringLevel\":1,\"status\":0,\"strengNumber\":0,\"timeDay\":16404,\"trade\":false,\"variables\":{\"@type\":\"java.util.HashMap\"},\"weddingRingAtt\":[]}";
Pattern testPattern = Pattern.compile("(\"attributes\":\\[[a-zA-z0-9\\{\\}]{0,100})");
Matcher testMatcher = testPattern.matcher(ss);
while(testMatcher.find()){
System.out.println(testMatcher.group(1));
}
真实情况会有很多个这样重复的字符串
我需要将所有的"attributes\":[{\"state\":0,\"type\":13,\"value\":10},{\"state\":0,\"type\":11,\"value\":1},{\"state\":0,\"type\":15,\"value\":1},{\"state\":0,\"type\":16,\"value\":1}]
提取出来,求教了
------解决思路----------------------
简单的方式:
String ss="{\"@type\":\"com.game.backpack.structs.Equip\",\"attributes\":[{\"state\":0,\"type\":13,\"value\":10},{\"state\":0,\"type\":11,\"value\":1},{\"state\":0,\"type\":15,\"value\":1},{\"state\":0,\"type\":16,\"value\":1}],\"automaticSellbind\":0,\"baptizeAttributes\":[],\"bind\":false,\"blessNum\":0,\"blessValue\":0,\"clearBlessNumDay\":16404,\"createTime\":1417322920,\"durability\":2147483647,\"equipBelongType\":2,\"equipInsure\":0,\"equipPos\":0,\"extendStr\":{\"@type\":\"java.util.HashMap\"},\"gradeNum\":0,\"gridId\":85,\"id\":5631562744724995728,\"itemCooldownMap\":{\"@type\":\"java.util.HashMap\"},\"itemModelId\":104080011,\"itemsShowTime\":0,\"jewels\":[],\"kingOil\":false,\"lost\":false,\"losttime\":0,\"num\":1,\"packageId\":0,\"parameters\":{\"@type\":\"java.util.HashMap\"},\"ringAttributes\":[],\"ringLevel\":1,\"status\":0,\"strengNumber\":0,\"timeDay\":16404,\"trade\":false,\"variables\":{\"@type\":\"java.util.HashMap\"},\"weddingRingAtt\":[]}";
String rgx = "(\"attributes\":\\[.*?\\])";
Pattern p = Pattern.compile(rgx);
Matcher m = p.matcher(ss);
while(m.find()){
System.out.println(m.group(1));
}