首页 > 其他分享 >获取url中指定参数的值

获取url中指定参数的值

时间:2022-09-07 23:44:29浏览次数:70  
标签:String url Pattern 获取 mXM 参数 result spm

import java.util.regex.Matcher;
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;
}

}

标签:String,url,Pattern,获取,mXM,参数,result,spm
From: https://www.cnblogs.com/koushijun575/p/16667745.html

相关文章