Pattern p = pattern.compile ("\ \ \" [\\w | / | : | . | ? | & | _ | % | =]*\\ ' \ \) ");
Matcher m = P.matcher ("<script>location.replace (' https://login.10086.cn/adduid.action?channelid=00791& backurl=http%3a%2f%2fservice.jx.10086.cn%3a80%2fservice%2fbackaction.action%3fmenuid%3d000200010003%26samlart% 3d021c3b40cac0451da521b81e1f4a27d0_15279252432%26relaystate%3dtype%3da%3bbackurl%3dhttp%3a%2f% 2fservice.jx.10086.cn%3a80%2fservice%2fbackaction.action%3fmenuid%3d000200010003%3bnl%3d6%26isencodepassword% 3d1%26displaypic%3d1%26displaypics%3dnull%26isencodemobile%3d1&artifact=2a47789396a74882b70ac2ea9b06e1f4 &transactionid=942153683 ');</script> ");
Matcher m = P.matcher ("<script>location.replace (' sdfdsf/:.? ')");
System.out.println (M.groupcount ());
if (M.find ()) {
System.out.println (M.group (0));
}else{
System.out.println ("no");
}
\ \ (indicates translation (
In fact, the regular expression is actually equivalent to writing if else judgment put all the cards in the middle, all the cases are written into
The personal feeling that the regular expression writing is good, is entirely in the understanding of the content of the match is comprehensive.
Java Regular Expressions