java取值
String a = "123[125]456[56]45[96]89"这种字符串,怎么把括号里面的值取出来呢?? 貌似用正则表达式会更简单,可惜我不会!
[解决办法]
正则
String a = "123[125]456[56]45[96]89";
String regex="(.*?)\\[(.*?)\\]";
Pattern p=Pattern.compile(regex);
Matcher m=p.matcher(a);
while(m.find()){
System.out.println(m.group(1));
System.out.println(m.group(2));
}
String a = "123[125[456[56]45[96]89]";
String regex="(.*?)[\\[\\]]{1}(.*?)[\\[\\]]{1}";
Pattern p=Pattern.compile(regex);
Matcher m=p.matcher(a);
while(m.find()){
System.out.println(m.group(1));
System.out.println(m.group(2));
}