static Matcher flattenNestedSequences(Matcher matcher) {
    if (matcher instanceof SeqMatcher) {
      List<Matcher> matchers = matcher.<SeqMatcher>as().matchers();
      List<Matcher> ms = new ArrayList<>();
      for (Matcher m : matchers) {
        if (m instanceof SeqMatcher) {
          ms.addAll(m.<SeqMatcher>as().matchers());
        } else {
          ms.add(m);
        }
      }
      return SeqMatcher.create(ms);
    }
    return matcher;
  }
static Matcher flattenNestedSequences ( Matcher matcher ) { if ( matcher instanceof SeqMatcher ) { List < Matcher > matchers = matcher . < SeqMatcher > as ( ) . matchers ( ) ; List < Matcher > ms = new ArrayList < > ( ) ; for ( Matcher m : matchers ) { if ( m instanceof SeqMatcher ) { ms . addAll ( m . < SeqMatcher > as ( ) . matchers ( ) ) ; } else { ms . add ( m ) ; } } return SeqMatcher . create ( ms ) ; } return matcher ; }
Since we do not need to capture the contents, nested sequences can be simplified to
a just a simple sequence. For example, {@code "a(b.*c)d" => "ab.*cd"}.