### Question:
Optimizer { static Matcher extractPrefixFromOr(Matcher matcher) { if (matcher instanceof OrMatcher) { List<Matcher> matchers = matcher.<OrMatcher>as().matchers(); if (matchers.isEmpty()) { return matcher; } Matcher prefix = PatternUtils.getPrefix(matchers.get(0)); if (prefix.alwaysMatches()) { return matcher; } List<Matcher> ms = new ArrayList<>(); ms.add(PatternUtils.getSuffix(matchers.get(0))); for (Matcher m : matchers.subList(1, matchers.size())) { Matcher p = PatternUtils.getPrefix(m); if (!prefix.equals(p)) { return matcher; } ms.add(PatternUtils.getSuffix(m)); } return SeqMatcher.create(prefix, OrMatcher.create(ms)); } return matcher; } private  Optimizer();   }### Answer:
@Test public void extractPrefixFromOr() { Matcher a = new CharSeqMatcher("a"); Matcher b = new CharSeqMatcher("b"); Matcher input = OrMatcher.create( new ZeroOrMoreMatcher(a, AnyMatcher.INSTANCE), new ZeroOrMoreMatcher(a, a), new ZeroOrMoreMatcher(a, b) ); Matcher expected = SeqMatcher.create( new ZeroOrMoreMatcher(a, TrueMatcher.INSTANCE), OrMatcher.create(AnyMatcher.INSTANCE, a, b) ); Assertions.assertEquals(expected, Optimizer.extractPrefixFromOr(input)); }