{"record":{"id":"a8bf615ae1974c5d","repo":"kestra-io/kestra","slug":"group-index-0-is-out-of-bounds-the-pattern-has","errorCode":null,"errorMessage":"Group index {0} is out of bounds: the pattern has only {1} capture group(s).","messagePattern":"Group index (.+?) is out of bounds: the pattern has only (.+?) capture group\\(s\\)\\.","errorType":"validation","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/filters/RegexExtractFilter.java","lineNumber":88,"sourceCode":"        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    }\n}\n","sourceCodeStart":70,"sourceCodeEnd":103,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/filters/RegexExtractFilter.java#L70-L103","documentation":"Thrown by the 'regexExtract' Pebble filter when the requested capture group index exceeds the number of capture groups in the compiled pattern. Group 0 (the whole match) is always available; this check fires only when `group` is greater than `matcher.groupCount()`, after a match has already been found.","triggerScenarios":"Asking for group 2 on a pattern with only one capture group; requesting a group on a pattern that has no capture groups at all (groupCount() == 0).","commonSituations":"Adding/removing parentheses in the regex without updating the group index; assuming the index is zero-based for capture groups (it is 1-based; 0 is the full match).","solutions":["Count the capture groups (each `(...)` is one) and use an index within range.","Use group 0 if you only need the full match.","Use named groups and reference them by name where supported."],"exampleFix":"# before - only 1 capture group\n{{ \"a-b\" | regexExtract(regex=\"(\\\\w+)\", group=2) }}\n# after\n{{ \"a-b\" | regexExtract(regex=\"(\\\\w+)\", group=1) }}","handlingStrategy":"validation","validationCode":"# Count capture groups in the pattern and clamp the index:\n# int max = matcher.groupCount();\n# int safeGroup = Math.min(Math.max(0, requested), max);\n{{ s | regexExtract(regex=\"(a)(b)\", group=1) }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Count `(...)` groups in the pattern; group index must be 0..groupCount().","Update the group index whenever you add or remove parentheses.","Use group 0 when you only need the full match."],"tags":["pebble-filter","regex-extract","group-index","out-of-bounds","regex"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}