Java Using regular expression to intercept content between specified strings :

package com.accord.util; import java.util.ArrayList; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Pattern; /** *
Regular expressions match between two strings * @author Administrator * */ public class RegexUtil { public
static void main(String[] args) { String str = "<?xml version='1.0'
encoding='UTF-8'?><ufinterface billtype='gl' filename='e:\1.xml' isexchange='Y'
proc='add' receiver='1060337@1060337-003' replace='Y' roottag='sendresult'
sender='01'
successful='Y'><sendresult><billpk></billpk><bdocid>w764</bdocid><filename>e:\1.xml</filename><resultcode>1</resultcode><resultdescription> bill w764 Start processing ... bill w764 Finished processing !</resultdescription><content>2017.09- Bookkeeping voucher -1</content></sendresult><sendresult><billpk></billpk><bdocid>w1007</bdocid><filename>e:\1.xml</filename><resultcode>1</resultcode><resultdescription> bill w1007 Start processing ... bill w1007 Finished processing !</resultdescription><content>2017.10- Bookkeeping voucher -1</content></sendresult><sendresult><billpk></billpk><bdocid>w516</bdocid><filename>e:\1.xml</filename><resultcode>1</resultcode><resultdescription> bill w516 Start processing ... bill w516 Finished processing !</resultdescription><content>2017.07- Bookkeeping voucher -50</content></sendresult></ufinterface>";
//String str = "abc3443abcfgjhgabcgfjabc"; String rgex =
"<bdocid>(.*?)</bdocid>"; System.out.println((new
RegexUtil()).getSubUtil(str,rgex)); List<String> lists = (new
RegexUtil()).getSubUtil(str,rgex); for (String string : lists) {
System.out.println(string); } System.out.println((new
RegexUtil()).getSubUtilSimple(str, rgex)); } /** * Regular expression matches the middle of two specified strings * @param
soap * @return */ public List<String> getSubUtil(String soap,String rgex){
List<String> list = new ArrayList<String>(); Pattern pattern =
Pattern.compile(rgex);// Matching pattern Matcher m = pattern.matcher(soap); while
(m.find()) { int i = 1; list.add(m.group(i)); i++; } return list; } /** *
Returns a single string , If there are more than one match, the first one will be returned , Methods and getSubUtil equally * @param soap * @param rgex * @return */
public String getSubUtilSimple(String soap,String rgex){ Pattern pattern =
Pattern.compile(rgex);// Matching pattern Matcher m = pattern.matcher(soap);
while(m.find()){ return m.group(1); } return ""; } }

Operation results :

[w764, w1007, w516]
w764
w1007
w516
w764

Technology
©2019-2020 Toolsou All rights reserved,
Python Basic knowledge and notes Programmer Tanabata Valentine's Day confession code NOI2019 travels China's longest high speed rail officially opened ! The fastest way to finish the race 30.5 hour C Language programming to find a student's grade Software testing BUG describe ESP8266/ESP32 System : Optimize system startup time Unity Scene loading asynchronously ( Implementation of loading interface ) Baidu , Ali , Tencent's internal position level and salary structure , With job suggestions !PYTHON Summary of final review