PatternUtil { public static String group(String content, String patternStr, int group){ Pattern pattern = null; if (!map.containsKey(patternStr)){ pattern = Pattern.compile(patternStr); } else { pattern = map.get(patternStr); } Matcher matcher = pattern.matcher(content); if (matcher.find()){ return matcher.group(group); } return null; }  static String group(String content, String patternStr, int group);  }
@Test public void group() { String s = "https: String regex = " String result = PatternUtil.group(s, regex, 1); String result1 = PatternUtil.group("http: Assert.assertEquals(result, "zhihu"); Assert.assertEquals(result1, "cn-proxy"); }