### Question:
Optimizer { static Matcher removeTrailingMatchAny(Matcher matcher) { if (matcher instanceof ZeroOrMoreMatcher) { ZeroOrMoreMatcher zm = matcher.as(); boolean atEnd = zm.next() instanceof TrueMatcher || zm.next() instanceof EndMatcher; if (atEnd && zm.repeated() instanceof AnyMatcher) { return TrueMatcher.INSTANCE; } } return matcher; } private  Optimizer();   }### Answer:
@Test public void removeTrailingMatchAny() { Matcher input = new ZeroOrMoreMatcher(AnyMatcher.INSTANCE, EndMatcher.INSTANCE); Matcher expected = TrueMatcher.INSTANCE; Assertions.assertEquals(expected, Optimizer.removeTrailingMatchAny(input)); }