50,526
社区成员
发帖
与我相关
我的任务
分享
String s="table('aa','bb',cc)+('ad.get()',ad.getid(),'ad.getdescription()')";
Pattern p=Pattern.compile(".*?\\((.*?)(?<!\\()\\)");
Matcher m=p.matcher(s);
while(m.find()){
System.out.println(m.group(1));
}
结果:
'aa','bb',cc
'ad.get()',ad.getid(),'ad.getdescription()'
String s="table('aa','bb',cc)+('ad.get()',ad.getid(),'ad.getdescription()')";
Pattern p=Pattern.compile(".*?\\((.*?)(?<!\\()\\)");
Matcher m=p.matcher(s);
while(m.find()){
System.out.println(m.group(1));
}
结果:
'aa','bb',cc
'ad.get()',ad.getid(),'ad.getdescription()'[/quote]
厉害~
public static void main(String arg[]) {
String string = "table('aa','bb',cc)+('ad.get()',ad.getid(),'ad.getdescription()')";
String regex = "\\((.*?)(?<!(\\()|\\()\\)";
Pattern pattern = Pattern.compile(regex);
Matcher m = pattern.matcher(string);
while (m.find()) {
System.out.println(m.group(1));
}
}
'aa','bb',cc
'ad.get()',ad.getid(),'ad.getdescription()'
String s = "table('aa','bb',cc)+('ad.get()',ad.getid(),'ad.getdescription()')";
Pattern ptn = Pattern.compile("\\+\\((.*?)\'\\)");
Matcher mather = ptn.matcher(s);
while (mather.find()) {
System.out.println(mather.group(1));//结果是'ad.get()',ad.getid(),'ad.getdescription(),少一个',可以System.out.println(mather.group(1)+"'");
}