RegExpExt { public static Function<String, Matcher> dynamicMatcher(Supplier<String> regExpSource, int flags, Consumer<Throwable> onError) { return dynamicMatcherInternal(regExpSource, flags, onError); } private  RegExpExt(); static Function<String, Matcher> dynamicMatcher(Supplier<String> regExpSource, int flags, Consumer<Throwable> onError); static Function<String, Matcher> dynamicMatcher(Supplier<String> regExpSource, String propertyName, int flags, Logger errorLogger);  }
@Test public void testDynamicMatcher() { String message = "hello\nend"; boolean matches = RegExpExt.dynamicMatcher(() -> ".*hello.*", Pattern.DOTALL, e -> { throw new IllegalStateException(e); }).apply(message).matches(); assertThat(matches).isTrue(); }
@Test public void testDynamicModifications() { String message = "hello\nend"; AtomicReference<String> config = new AtomicReference<>(".*hello.*"); Function<String, Matcher> matcher = RegExpExt.dynamicMatcher(() -> config.get(), Pattern.DOTALL, e -> { throw new IllegalStateException(e); }); assertThat(matcher.apply(message).matches()).isTrue(); config.set(".*foobar.*"); assertThat(matcher.apply(message).matches()).isFalse(); }