Java 多个相同关键字进行文字识别

public static void main(String[] args) throws Exception{
String strText = "被申请人:第一家测试有限公司。 住所地:第一家测试有限公司地址,统一社会信用 代码:123456789。 联系电话:1111. 被申请人:第二家测试有限公司(历史名称: 测试公司)。 住所地:第二家测试有限公司地址,统一 社会信用代码:123456。 联系电话:1234567. 被申请人:第三季(测试)有限公司。 住所地:第三家测试公司地址,统一社会信用代码:123456。 联系电话:123456. 申请事项:等等后续文字年月日。。。";
String regex = "[\\.,。]";
String applicantName = "";
String information = "";
int ind = -1;
String sss = strText.substring(0,strText.indexOf("申请事项"));
int count = 0;
Pattern p = Pattern.compile("被申请人");
Matcher m = p.matcher(sss);
while (m.find()){
count++;
}
if(strText.contains("被申请人") && strText.contains("申请事项")) {
if (count >= 2){
for (int i = 0; i < count; i++) {
if(strText.contains("被申请人:") || strText.contains("被申请人:")) {
information = strText.substring(strText.indexOf("被申请人")+5,strText.indexOf("申请事项")+4);
}else {
information = strText.substring(strText.indexOf("被申请人")+4);
}
if (information.matches (".*" + regex + ".*"))
{
ind = information.split (regex)[0].length ();
}
applicantName = information.substring(0,ind);
strText = information.substring(applicantName.length()+1, information.length()).replace(" ","");
System.out.println(applicantName);

//第一家测试有限公司
//第二家测试有限公司(历史名称:测试公司)
//第三季(测试)有限公司


}
}
}
}

posted on 2023-04-18 15:41  多言  阅读(39)  评论(0编辑  收藏  举报

导航