【AL_Child】【Cols=2】
............
【/AL_Child】
我有这样一个字符串,用正则表达式怎么样能够提取出【AL_*****】 …… 【/AL_*****】里面的字符串
需要提取出来的字符串包括:1,AL_后面(星号)的字符串;2,AL标签里面(省略号)的字符串请大家帮帮忙,谢谢了。String src=............;//原串String str="【AL\\((.*?)\\)】([\\s\\S]*?)【\\/AL\\((.*?)\\)】";Pattern p=Pattern.compile(str,Pattern.CASE_INSENSITIVE);
Matcher m=p.matcher(src);
while(m.find()){
List lst=new ArrayList();
int i=0;
Object obj=m.group(i);
while(obj!=null){
lst.add((String)obj);
i++;
obj=m.group(i);
}
}
这样写好像不能得到结果,请大家指点,应该咋提取啊?谢谢了。
............
【/AL_Child】
我有这样一个字符串,用正则表达式怎么样能够提取出【AL_*****】 …… 【/AL_*****】里面的字符串
需要提取出来的字符串包括:1,AL_后面(星号)的字符串;2,AL标签里面(省略号)的字符串请大家帮帮忙,谢谢了。String src=............;//原串String str="【AL\\((.*?)\\)】([\\s\\S]*?)【\\/AL\\((.*?)\\)】";Pattern p=Pattern.compile(str,Pattern.CASE_INSENSITIVE);
Matcher m=p.matcher(src);
while(m.find()){
List lst=new ArrayList();
int i=0;
Object obj=m.group(i);
while(obj!=null){
lst.add((String)obj);
i++;
obj=m.group(i);
}
}
这样写好像不能得到结果,请大家指点,应该咋提取啊?谢谢了。
String regex = "【AL_([^【]*)】【Cols=2】(.*)【/AL_[^【]*】";
String str = "【AL_Child】【Cols=2】SDFSDFSDF【/AL_Child】 ";
Pattern p=Pattern.compile(regex,Pattern.CASE_INSENSITIVE);
Matcher m=p.matcher(str);
while(m.find()){
System.out.println(m.group(1)+"|"+m.group(2));
}
List<String> temp = new ArrayList<String>();
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
while(m.find()){
temp.add(m.group());
}
String[] result=new String[temp.size()];
temp.toArray(result);
return result;
} public static void main(String[] a){
String regex="AL.*/AL";
String str="123ALvcv/AL75942A8506B4213";
String[] result=getStrExpression(regex,str);
for(String s:result){
System.out.println(s);
}
}
String regex="AL.*\\/AL";