public static String extractSubstring(String input, String pattern) {
Pattern regexPattern = Pattern.compile(pattern);
Matcher matcher = regexPattern.matcher(input);
if (matcher.find()) {
return matcher.group(1);
}
return null;
}
input和pattern举例。为了提取“/p/erkezonghe.html”中的
erkezonghe,用模板
"/p/(.*?).html"去匹配。提取的就是括号中间的一部分,锚点是括号左右的东西。标签:匹配,String,Pattern,pattern,matcher,字符串,input From: https://www.cnblogs.com/easycoding20211115/p/17600505.html