有这么一字符串例:String str = "<script>parent.setGoalAlertStatus(false);parent.od_Data[1].s = [4303];parent.od_Data[1].c = [[[4,'ITALY SERIE A',0], [ [722901,'Brescia','Inter Milan','1.010',6,'03/12/2011 03:45',0,4,1,0,'SG: CH202 MY: ASTRO816 IDN]]]]];have more chars";
//字符串的内容是多变的,这里只是举个例子。
想求得以 [[[ 开头 ]]]]]结尾 子字符串。以上面为例,我要取得[[4,'ITALY SERIE A',0], [ [722901,'Brescia','Inter Milan','1.010',6,'03/12/2011 03:45',0,4,1,0,'SG: CH202 MY: ASTRO816 IDN]]]]] 这么一段
//字符串的内容是多变的,这里只是举个例子。
想求得以 [[[ 开头 ]]]]]结尾 子字符串。以上面为例,我要取得[[4,'ITALY SERIE A',0], [ [722901,'Brescia','Inter Milan','1.010',6,'03/12/2011 03:45',0,4,1,0,'SG: CH202 MY: ASTRO816 IDN]]]]] 这么一段
Pattern p = Pattern.compile(".+(\\[\\[.+\\]\\]\\]\\]\\]).+");
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group(1));
}
public static void main(String[] args) {
String str = "<script>parent.setGoalAlertStatus(false);parent.od_Data[1].s = " +
"[4303];parent.od_Data[1].c = [[[4,'ITALY SERIE A',0], [ [722901" +
",'Brescia','Inter Milan','1.010',6,'03/12/2011 03:45',0,4,1,0,'SG: CH202&" +
"#13;MY: ASTRO816 IDN]]]]];have more chars";
String regex = "\\[{2,}.*\\]{2,}";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
while(m.find()) {
System.out.println(m.group());
}
}