2014年5月22日星期四

Regex help

For example: the following string to split " Plaintiff: Liuwen Gan ; Defendant: Yuecao Ming , Zhang month, Yong An Property Insurance Co., Ltd. Haining branch ."
string rule: order the plaintiff and the defendant are not fixed ( likely the first defendant , the plaintiff in the post) , the plaintiff can be written as the appellant , the applicant , the public prosecutor ( collectively, the plaintiff keyword ) , the defendant can be written as a defendant , respondent , the respondent ( collectively, the defendant keyword )
split rule: between the defendant to the plaintiff keyword keyword ( or end ) of the plaintiff , the defendant keyword to the end ( or between the plaintiff keyword ) for the defendant.
My current approach: 1, plaintiff , defendant keyword unified replaced plaintiff , defendant. 2, using indexOf processing. But this is too cumbersome , and later tried to use regular expressions to write, or a problem .

String str = "上诉人:刘文淦;被申请人:岳曹明,张惠月,永安财产保险股份有限公司海宁支公司";
str = str.replaceAll("(被告|被告人|被上诉人|被申请人)", "被告");
str = str.replaceAll("(原告|上诉人|申请人|公诉人)", "原告");
Pattern p = Pattern.compile("(?<=原告)(.*)(?<=被告)(.*)");
Matcher m = p.matcher(str);
while(m.find()){
   System.out.println(m.group(1));
   System.out.println(m.group(2));
}

Which person familiar with the regular help
------ Solution --------------------------- -----------------
what to get ah ?
------ For reference only -------------------------------------- -

split the original defendant , the following results
Plaintiff: Liuwen Gan
Defendant: Yuecao Ming , Zhang month, Yong An Property Insurance Co., Ltd. Haining branch
------ For reference only ----------------- ----------------------
not regular

String str = "上诉人:刘文淦;被申请人:岳曹明,张惠月,永安财产保险股份有限公司海宁支公司";
String[] t =str.split(";");
for (String s : t) {
System.out.println(s);
}

------ For reference only ----------------------------------- ----
String str = "上诉人:刘文淦;被申请人:岳曹明,张惠月,永安财产保险股份有限公司海宁支公司";
System.err.println(str.replaceAll("(.*);(.*)", "$1------>$2"));;

------ For reference only ---------------------------- -----------


amount sorry there is not necessarily a semicolon between a rule , the plaintiff and the defendant , there may be a line break or other symbols.
------ For reference only -------------------------------------- -
so how do you distinguish between the end of the ah.
------ For reference only -------------------------------------- -
can not see
//String str = "上诉人:刘文淦;被申请人:岳曹明,张惠月,永安财产保险股份有限公司海宁支公司";
 String str = "被申请人:岳曹明,张惠月|上诉人:刘文淦,永安财产保险股份有限公司海宁支公司";
 System.err.println(str.replaceAll("(.*)(.)(被告|被告人|被上诉人|被申请人|原告|上诉人|申请人|公诉人)(.*)", "$1------>$3$4"));;

------ For reference only ----------------------------------- ----


Yes, I would like to do a little adjustment . Results posted Thanks

没有评论:

发表评论