public static void main(String[] args) { String key = "姓名"; String orgin = "姓名:王五,"; String reg = key + ":([^,]+),"; Pattern p = Pattern.compile(reg); Matcher matcher = p.matcher(orgin); if (matcher.find()) { System.out.println(matcher.group(1)); } else { System.out.println("null"); } } |
|