lyyb2001

只是为方便自己找记录而已
posts - 57, comments - 27, trackbacks - 0, articles - 5
  BlogJava :: 首页 :: 新随笔 :: 联系 ::  :: 管理

正则匹配

Posted on 2015-03-27 10:41 skycity 阅读(108) 评论(0)  编辑  收藏 所属分类: J2EE技术
@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

只有注册用户登录后才能发表评论。


网站导航: