@import url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
public static String readString = "Print([QDT],[Read([SQLServer#10.176.1.178#Mas2006],[select top 1 print_model + '.jasper' as reportname from tbl_mas_print_stru where Machine_No='SS110521Z8'],['@@Lang'])],[Read([SQLServer#10.176.1.178#Mas2006],[select Machine_No, Check_Code, Model_Packing, Start_Date, Material_Name, Material_No, IIPC_part_code, Material_Qty, Print_Order, Machine_Product_No, print_model, SoftWareName, SoftWare_No, SoftWareQty from dbo.tbl_mas_print_stru where Machine_No='SS110521Z8'],['@@Lang'])])";
public static void splitScriptWithMethod(String script) {
// check if args
String subMethodReg = "";
if(script.indexOf("Read([") !=script.lastIndexOf("Read([")){
subMethodReg = "(.+)\\(\\[(.+)\\],\\[(.+\\(\\[.+\\]\\))\\],\\[(.+\\(\\[.+\\]\\))\\]";
}else{
subMethodReg = "(.+)\\(\\[(.+)\\],\\[(.+)\\],\\[(.+\\(\\[.+\\]\\))\\]";
}
Pattern p = Pattern.compile(subMethodReg);
Matcher matcher = p.matcher(readString);
while (matcher.find()) {
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("grp " + i + " :" + matcher.group(i));
}
}
}
grp 1 :Print
grp 2 :QDT
grp 3 :Read([SQLServer#10.176.1.178#Mas2006],[select top 1 print_model + '.jasper' as reportname from tbl_mas_print_stru where Machine_No='SS110521Z8'],['@@Lang'])
grp 4 :Read([SQLServer#10.176.1.178#Mas2006],[select Machine_No, Check_Code, Model_Packing, Start_Date, Material_Name, Material_No, IIPC_part_code, Material_Qty, Print_Order, Machine_Product_No, print_model, SoftWareName, SoftWare_No, SoftWareQty from dbo.tbl_mas_print_stru where Machine_No='SS110521Z8'],['@@Lang'])
其中,用于匹配(.+)\\(\\[(.+)\\],\\[(.+\\(\\[.+\\]\\))\\],\\[(.+\\(\\[.+\\]\\))\\],print([],[Read([],[],[])],[Read([],[],[])])这样的结构
而(.+)\\(\\[(.+)\\],\\[(.+)\\],\\[(.+\\(\\[.+\\]\\))\\],用于匹配print([],[],[Read([],[],[])]这样的结构
Lyyb2001