{"record":{"id":"795bc140102577b8","repo":"kestra-io/kestra","slug":"invalid-regex-0-1","errorCode":null,"errorMessage":"Invalid regex '{0}': {1}","messagePattern":"Invalid regex '(.+?)': (.+?)","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/filters/RegexExtractFilter.java","lineNumber":83,"sourceCode":"        String regex = args.get(ARGUMENT_REGEX).toString();\n        int group = args.containsKey(ARGUMENT_GROUP) && args.get(ARGUMENT_GROUP) != null\n            ? ((Number) args.get(ARGUMENT_GROUP)).intValue()\n            : 0;\n\n        if (group < 0) {\n            throw new PebbleException(\n                null,\n                MessageFormat.format(\"Group index {0} is out of bounds: must be >= 0.\", group),\n                lineNumber,\n                self.getName()\n            );\n        }\n\n        Matcher matcher;\n        try {\n            matcher = RegexUtils.matcher(Pattern.compile(regex), input.toString());\n        } catch (PatternSyntaxException e) {\n            throw new PebbleException(e, MessageFormat.format(\"Invalid regex ''{0}'': {1}\", regex, e.getDescription()), lineNumber, self.getName());\n        }\n        try {\n            if (matcher.find()) {\n                if (group > matcher.groupCount()) {\n                    throw new PebbleException(\n                        null,\n                        MessageFormat.format(\"Group index {0} is out of bounds: the pattern has only {1} capture group(s).\", group, matcher.groupCount()),\n                        lineNumber,\n                        self.getName()\n                    );\n                }\n                return matcher.group(group);\n            }\n        } catch (RegexUtils.RegexTimeoutException e) {\n            throw new PebbleException(e, e.getMessage(), lineNumber, self.getName());\n        }\n        return null;\n    }","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/filters/RegexExtractFilter.java#L65-L101","documentation":"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').","triggerScenarios":"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`).","commonSituations":"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.","solutions":["Double-escape backslashes in Pebble literals: write `\\\\d` for `\\d`.","Test the pattern in a Java regex tester first.","If the pattern is complex, pass it via an input or variable to avoid double-escaping pain."],"exampleFix":"# before\n{{ s | regexExtract(regex=\"\\d+\") }}\n# after\n{{ s | regexExtract(regex=\"\\\\d+\") }}","handlingStrategy":"validation","validationCode":"# Test the pattern compiles in a script task before using it in the template:\n# Pattern.compile(userPattern);  // throws PatternSyntaxException early with full detail\n# In Pebble, always double-escape:\n{{ s | regexExtract(regex=\"\\\\d+\") }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Double-escape backslashes in Pebble regex literals (`\\\\d`, `\\\\.`).","Validate patterns in a Java regex tester before embedding.","For complex patterns, pass them via a variable/input to centralise escaping."],"tags":["pebble-filter","regex-extract","invalid-regex","pattern-syntax","escaping"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}