{"record":{"id":"74dd48cf4f3aa24c","repo":"karatelabs/karate","slug":"extractall-needs-three-arguments-text-regex-group","errorCode":null,"errorMessage":"extractAll() needs three arguments: text, regex, group","messagePattern":"extractAll\\(\\) needs three arguments: text, regex, group","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java","lineNumber":165,"sourceCode":"            if (args.length < 3) {\n                throw new RuntimeException(\"extract() needs three arguments: text, regex, group\");\n            }\n            String text = args[0].toString();\n            String regex = args[1].toString();\n            int group = ((Number) args[2]).intValue();\n            Pattern pattern = Pattern.compile(regex);\n            Matcher matcher = pattern.matcher(text);\n            if (!matcher.find()) {\n                return null;\n            }\n            return matcher.group(group);\n        };\n    }\n\n    static JavaInvokable extractAll() {\n        return args -> {\n            if (args.length < 3) {\n                throw new RuntimeException(\"extractAll() needs three arguments: text, regex, group\");\n            }\n            String text = args[0].toString();\n            String regex = args[1].toString();\n            int group = ((Number) args[2]).intValue();\n            Pattern pattern = Pattern.compile(regex);\n            Matcher matcher = pattern.matcher(text);\n            List<String> list = new ArrayList<>();\n            while (matcher.find()) {\n                list.add(matcher.group(group));\n            }\n            return list;\n        };\n    }\n\n    static JavaInvokable filter() {\n        return args -> {\n            if (args.length < 2) {\n                throw new RuntimeException(\"filter() needs two arguments: list and function\");","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java#L147-L183","documentation":"Karate's extractAll() JS utility applies a regex to text and collects a capture group from every match. It requires three arguments — text, regex, and group index — and throws this error when fewer are supplied.","triggerScenarios":"Calling extractAll(text, regex) without the group number, or with only the text, or with no arguments.","commonSituations":"Assuming a default group of 1 or 0; converting code from extract() and dropping the group accidentally; dynamic regex-building helpers that forget the group argument.","solutions":["Supply the group index: extractAll(text, 'pattern', 1)","Use 0 to capture entire matches","Ensure all matches are wanted — for a single match use extract() instead"],"exampleFix":"// before\nvar ids = karate.extractAll(body, '\"id\":(\\\\d+)');\n// after\nvar ids = karate.extractAll(body, '\"id\":(\\\\d+)', 1);","handlingStrategy":"validation","validationCode":"if (text == null || regex == null || group == null) throw new Error('extractAll requires text, regex and group');","typeGuard":"function canExtractAll(args) { return args.length >= 3 && typeof args[1] === 'string' && typeof args[2] === 'number'; }","tryCatchPattern":"try { ids = karate.extractAll(text, regex, 1); } catch (e) { karate.log('extractAll failed: ' + e.message); }","preventionTips":["Always pass the group argument explicitly","Use extract() when only the first match is needed","Validate the regex compiles before using it in tests"],"tags":["argument-count","regex","javascript","karate"],"backgroundTag":"missing-required-argument","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}