import java.util.regex.Matcher;标签:String,url,Pattern,获取,mXM,参数,result,spm From: https://www.cnblogs.com/koushijun575/p/16667745.html
import java.util.regex.Pattern;
public class url {
public static void main(String[] args) {
String url="https://blog.csdn.&hybr=gl_home_en&net/qq_25004825/article/details/126031801?spm=1001";
String spm="hybr";
System.out.println(getFieldValue(url,spm));
}
private static String getFieldValue(String urlStr, String field) {
String result = "";
Pattern pXM = Pattern.compile(field + "=([^&]*)");
Matcher mXM = pXM.matcher(urlStr);
while (mXM.find()) {
result += mXM.group(1) + "\t\t";
}
return result;
}
}