开发者

Extracting a part of string in java

开发者 https://www.devze.com 2023-02-16 08:33 出处:网络
I am having the following data in a text file: proc sort data=oneplan.cust_duplicates(dbindex=yes) out=mibatch.cust_duplicates;

I am having the following data in a text file:

 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

Now i need to fetch the part from each line which starts with oneplan. and ends with a space.

Also if the line has two onep开发者_StackOverflow社区lan. then each must be extracted separately.

Example: agtut oneplan.m htyutu oneplan.j hgyut

i need the output as: oneplan.m and oneplan.j

kindly give me suggestions in doing this please...


You could use a regex like:

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));
}

Will print the results:

oneplan.f
oneplan.d
oneplan.m
oneplan.m
oneplan.a
oneplan.a
oneplan.a
oneplan.r
oneplan.f

If you instead want the entire word you can use matcher.group() in combination with the regex:

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


You can start with BufferedReader#readLine and String#startsWith String#endsWith.


Take a look at the various String.indexOf() and String.substring() methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号