直接贴代码吧
public class URLUtils {
/**
* 获取指定url中的某个参数
*
* @param url
* @param name
* @return
*/
public static String getParamByUrl(String url, String name) {
url += "&";
String pattern = "(\\?|&){1}#{0,1}" + name + "=[a-zA-Z0-9]*(&{1})";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(url);
if (m.find()) {
//System.out.println(m.group(0));
return m.group(0).split("=")[1].replace("&", "");
} else {
return null;
}
}
}
标签:return,String,URL,Pattern,url,参数,某个,group,name From: https://blog.51cto.com/u_14906615/5899419