JAVA 获取 URL 指定参数的值
JAVA 获取 URL 指定参数的值
@Test void regexTest() { String url = "https://www.cnblogs.com/vipsoft/p/15213397.html?name=abc&age=123"; String result = getFieldValue(url, "name"); logger.info(result); }
/** * 获取字段值 * * @param urlStr * @param field * @return */ 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; }
本文来自博客园,作者:VipSoft 转载请注明原文链接:https://www.cnblogs.com/vipsoft/p/15213397.html