The
Gets the character content of a part of a string, usually the first thought of using the String.substring method, but the String.substring method is not perfect for some of the processing that contains special characters and HTML tags. For example, the following string, want to get the characters in sign, string.substring method can also get the content of sign, but there are defects ....
String str= "<form id= ' frmbankid ' name= ' frmbankname ' method= ' post ' action= ' partner=\ '" 2088121205591541\ "& Seller_id=\ "2088121205591541\" &out_trade_no=\ fi104010001030900000007\ "\ n" +
"&subject=\"????? \ "&body=\"??? -?? 1.6 mt\ "&total_fee=\" 0.20\ "¬ify_url=\" "Http://func91fcw.vfinance.cn/server/alipay10401-vs.htm\" & Service=\ "mobile.securitypay.pay\" &payment_type=\ "1\" \ +
& nbsp "&_input_charset=\" utf-8\ "&it_b_pay=\" 30m\ "&show_url=\" m.alipay.com\ "\ n" +
"&sign=\" ianzm3toiunjf%2b5%2fxbanh3prneonhuedwlwuicfwae5lbezzg% 2bp2zeo6d7o36pzhrrya%2bzyjumdnfeuahyc79cxngkyeyo4%2fqa6ze0iktqswvogel24%2bokl%2bf%2fvoemkapkag% 2fmgfn8cacu4xw39td0kznusjo1if0kec8drwqvq%3d\ "\ n" +
"& Sign_type=\ "Rsa\" ' ></form> ';
String.substring Intercept:
int S=str.indexof ("sign=");
int T=str.indexof ("&sign_type");
String sign= str.substring (s+5,t-1);
System.out.println ("sign===" +sign);
Regular expression interception:
Pattern p = pattern.compile ("sign\\=\" (. *?) \ "");//Regular expression
Matcher m = p.matcher (str);
while (M.find ()) {
System.out.println (M.group (1));//m.group (1) does not include these two characters
}
M.group () gets all of the content including sign=