kestra-io/kestra · error · PebbleException

Invalid regex '{0}': {1}

Error message

Invalid regex '{0}': {1}

What it means

Thrown by the 'regexExtract' Pebble filter when `Pattern.compile(regex)` raises a `PatternSyntaxException`. The message embeds the offending pattern and the JDK's description of the syntax error (e.g. 'Unclosed group', 'Unexpected character').

Source

Thrown at core/src/main/java/io/kestra/core/runners/pebble/filters/RegexExtractFilter.java:83

        String regex = args.get(ARGUMENT_REGEX).toString();
        int group = args.containsKey(ARGUMENT_GROUP) && args.get(ARGUMENT_GROUP) != null
            ? ((Number) args.get(ARGUMENT_GROUP)).intValue()
            : 0;

        if (group < 0) {
            throw new PebbleException(
                null,
                MessageFormat.format("Group index {0} is out of bounds: must be >= 0.", group),
                lineNumber,
                self.getName()
            );
        }

        Matcher matcher;
        try {
            matcher = RegexUtils.matcher(Pattern.compile(regex), input.toString());
        } catch (PatternSyntaxException e) {
            throw new PebbleException(e, MessageFormat.format("Invalid regex ''{0}'': {1}", regex, e.getDescription()), lineNumber, self.getName());
        }
        try {
            if (matcher.find()) {
                if (group > matcher.groupCount()) {
                    throw new PebbleException(
                        null,
                        MessageFormat.format("Group index {0} is out of bounds: the pattern has only {1} capture group(s).", group, matcher.groupCount()),
                        lineNumber,
                        self.getName()
                    );
                }
                return matcher.group(group);
            }
        } catch (RegexUtils.RegexTimeoutException e) {
            throw new PebbleException(e, e.getMessage(), lineNumber, self.getName());
        }
        return null;
    }

View on GitHub (pinned to 823fada927)

Solutions

  1. Double-escape backslashes in Pebble literals: write `\\d` for `\d`.
  2. Test the pattern in a Java regex tester first.
  3. If the pattern is complex, pass it via an input or variable to avoid double-escaping pain.

Example fix

# before
{{ s | regexExtract(regex="\d+") }}
# after
{{ s | regexExtract(regex="\\d+") }}
Defensive patterns

Strategy: validation

Validate before calling

# Test the pattern compiles in a script task before using it in the template:
# Pattern.compile(userPattern);  // throws PatternSyntaxException early with full detail
# In Pebble, always double-escape:
{{ s | regexExtract(regex="\\d+") }}

Prevention

When it happens

Trigger: Passing a malformed regex: unbalanced parentheses, invalid quantifiers, bad character classes, or escaping mistakes from Pebble's own string parsing (e.g. writing `\d` instead of `\\d`).

Common situations: Pebble string escaping eats a backslash, turning `\d` into `d`; copy-pasting a regex from JS/Python without re-escaping; using lookahead/lookbehind that the JDK regex engine does not support in the same form.

Related errors


AI-assisted analysis of kestra-io/kestra@823fada927 (2026-08-14). Data as JSON: /api/errors/795bc140102577b8. Report an issue: GitHub.