code: static Pattern compileLogFileRegex(String baseName, String extension) {
          StringBuilder builder = new StringBuilder();
  
          // filename (dots escaped)
          builder.append(Pattern.quote(baseName));
  
          // _yy.MM.dd_HH.mm.ss
          builder.append("(_\\d\\d\\.\\d\\d\\.\\d\\d_\\d\\d\\.\\d\\d\\.\\d\\d)");
  
          // numeric identifier
          builder.append("(?:\\.(\\d+))");
  
          // extension (dots escaped)
          builder.append(Pattern.quote(extension));
  
          return Pattern.compile(builder.toString());
      }
docs: Compiles a pattern that can be used to match rolled over log file names.
  The first capturing group is the date/time string, and the second
  capturing group is the ID.
  
  @param baseName the log file basename (e.g., "messages")
  @param extension the log file extension (e.g., ".log")
  @param idOptional true if the rollover ID is optional
  @return