📜  java regex 检查组是否存在 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:26.258000             🧑  作者: Mango

代码示例1
String  text    = "asdf 2013-05-12 asdf";
String  regex   = ".+?([0-9]{4}\\s?-\\s?[0-9]{2}\\s?-\\s?[0-9]{2}).+";
Matcher matcher = Pattern.compile(regex).matcher(text);

if (matcher.matches()) {
    String matchedGroup = matcher.group(1);
    System.out.println(matchedGroup);
}