在java中提取字符串的一部分

在java中提取字符串的一部分,java,Java,我的文本文件中包含以下数据: proc sort data=oneplan.cust_duplicates(dbindex=yes) out=mibatch.cust_duplicates; from oneplan.fsa_authorised_agencies (dbindex=yes) set oneplan.fsa_agency_permissions(where=(regulated_activity in ('103','106','107','108')));

我的文本文件中包含以下数据:

 proc sort data=oneplan.cust_duplicates(dbindex=yes) out=mibatch.cust_duplicates;
    from oneplan.fsa_authorised_agencies (dbindex=yes) 
    set oneplan.fsa_agency_permissions(where=(regulated_activity in ('103','106','107','108')));
    set oneplan.customer_flags(where=(flag_id in(54,14,34)));
    from oneplan.document_history (dbindex=yes) 
    set oneplan.product_references;
  proc sort data=oneplan.fast_track_log(where=(upcase(business_entry)="INCOME VERIFICATION FAST TRACKED"))   out=fast_track_log;
    set oneplan.product_characteristics(rename=(value=filler)where=(characteristic_type="OFFS" ));
    set oneplan.mtg_offset_benefits (where=(modified_date between &extractdate and &batchcutoff) 
      from oneplan.mtg_payment_options a;
    from oneplan.acc_retention_risk acr;
    from oneplan.acc_retention_risk_hist acr;
    from oneplan.account_repay_veh rv;
    from oneplan.repay_vehicle_map rvm;
    from oneplan.frozen_accounts as fa left join mibatch.accounts as a
现在我需要从每行中提取零件,该行以
oneplan.
开头,以空格结尾

此外,如果该行有两个
oneplan.
,则必须分别提取每个计划

示例:
agtu oneplan.m htyutu oneplan.j hgyut

我需要输出为:
oneplan.m
oneplan.j


请给我一些建议…

你可以从和字符串#endsWith开始。

你可以从和字符串#endsWith开始。

看看各种
String.indexOf()
String.substring()
方法。

看看各种
String.indexOf()
String.substring()
方法。

您可以使用如下正则表达式:

String text = ....
String regex = "(oneplan\\.\\w)\\w+\\s+";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(text);
while(matcher.find()) {
   System.out.println(matcher.group(1));
}
将打印结果:

oneplan.f
oneplan.d
oneplan.m
oneplan.m
oneplan.a
oneplan.a
oneplan.a
oneplan.r
oneplan.f
如果您想要整个单词,可以将
matcher.group()
与正则表达式结合使用:

"oneplan\\.\\w+\\s+"

您可以使用以下正则表达式:

String text = ....
String regex = "(oneplan\\.\\w)\\w+\\s+";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(text);
while(matcher.find()) {
   System.out.println(matcher.group(1));
}
将打印结果:

oneplan.f
oneplan.d
oneplan.m
oneplan.m
oneplan.a
oneplan.a
oneplan.a
oneplan.r
oneplan.f
如果您想要整个单词,可以将
matcher.group()
与正则表达式结合使用:

"oneplan\\.\\w+\\s+"

这是家庭作业吗?如果有,应该有家庭作业标签。这是家庭作业吗?如果是的话,应该有一个家庭作业标签。如果你想知道如何使用正则表达式,请看这篇文章:如果你想知道如何使用正则表达式,请看这篇文章: