public Result runExtractor(String value) {
        final Matcher matcher = pattern.matcher(value);

        final boolean found = matcher.find();
        if (!found) {
            return null;
        }

        final int start = matcher.groupCount() > 0 ? matcher.start(1) : -1;
        final int end = matcher.groupCount() > 0 ? matcher.end(1) : -1;

        final String s;
        try {
            s = replaceAll ? matcher.replaceAll(replacement) : matcher.replaceFirst(replacement);
        } catch (Exception e) {
            throw new RuntimeException("Error while trying to replace string", e);
        }

        return new Result(s, start, end);
    }
@Test
    public void testReplacementWithReplaceAll() throws Exception {
        final Message message = messageFactory.createMessage("Foobar 123 Foobaz 456", "source", Tools.nowUTC());
        final RegexReplaceExtractor extractor = new RegexReplaceExtractor(
                metricRegistry,
                "id",
                "title",
                0L,
                Extractor.CursorStrategy.COPY,
                "message",
                "message",
                ImmutableMap.<String, Object>of("regex", "(\\w+) (\\d+)", "replacement", "$2/$1", "replace_all", true),
                "user",
                Collections.<Converter>emptyList(),
                Extractor.ConditionType.NONE,
                null);
        extractor.runExtractor(message);

        assertThat(message.getMessage()).isEqualTo("123/Foobar 456/Foobaz");
    }