• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Java | Regular expressions
  1. References
  2. Example: Groups

  1. References
    See this page for more details java regular expressions:
    https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/util/regex/Pattern.html
  2. Example: Groups
    final Pattern pattern = Pattern.compile("^([a-zA-Z]+)? (\\w+)$");
    
    final Matcher matcher = pattern.matcher("ABC _012_");
    
    if (matcher.matches()) {
        final String group1 = matcher.group(1);
        final String group2 = matcher.group(2);
    
        System.out.println(group1);
        System.out.println(group2);
    }
© 2025  mtitek