karatelabs/karate · error · RuntimeException

extractAll() needs three arguments: text, regex, group

Error message

extractAll() needs three arguments: text, regex, group

What it means

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.

Solutions

  1. Supply the group index: extractAll(text, 'pattern', 1)
  2. Use 0 to capture entire matches
  3. Ensure all matches are wanted — for a single match use extract() instead

Example fix

// before
var ids = karate.extractAll(body, '"id":(\\d+)');
// after
var ids = karate.extractAll(body, '"id":(\\d+)', 1);
Defensive patterns

Strategy: validation

Validate before calling

if (text == null || regex == null || group == null) throw new Error('extractAll requires text, regex and group');

Type guard

function canExtractAll(args) { return args.length >= 3 && typeof args[1] === 'string' && typeof args[2] === 'number'; }

Try / catch

try { ids = karate.extractAll(text, regex, 1); } catch (e) { karate.log('extractAll failed: ' + e.message); }

Prevention

When it happens

Trigger: Calling extractAll(text, regex) without the group number, or with only the text, or with no arguments.

Common situations: 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.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/74dd48cf4f3aa24c. Report an issue: GitHub.

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java:165

            if (args.length < 3) {
                throw new RuntimeException("extract() needs three arguments: text, regex, group");
            }
            String text = args[0].toString();
            String regex = args[1].toString();
            int group = ((Number) args[2]).intValue();
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(text);
            if (!matcher.find()) {
                return null;
            }
            return matcher.group(group);
        };
    }

    static JavaInvokable extractAll() {
        return args -> {
            if (args.length < 3) {
                throw new RuntimeException("extractAll() needs three arguments: text, regex, group");
            }
            String text = args[0].toString();
            String regex = args[1].toString();
            int group = ((Number) args[2]).intValue();
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(text);
            List<String> list = new ArrayList<>();
            while (matcher.find()) {
                list.add(matcher.group(group));
            }
            return list;
        };
    }

    static JavaInvokable filter() {
        return args -> {
            if (args.length < 2) {
                throw new RuntimeException("filter() needs two arguments: list and function");

View on GitHub (pinned to a22eb90246)