目录

@typescript-eslint/prefer-regexp-exec

Enforce RegExp#exec over String#match if no global flag (/g) is provided.

Rule Configuration

// code-linter.json5
{
  "rules": {
    "@typescript-eslint/prefer-regexp-exec": "error"
  }
}

Options

This rule is not configurable.

Example of Correct Code

/thing/.exec('something');

'some things are just things'.match(/thing/g);

const text = 'something';
const search = /thing/;
search.exec(text);

Example of Incorrect Code

'something'.match(/thing/);

'some things are just things'.match(/thing/);

const text = 'something';
const search = /thing/;
text.match(search);

Rule Set

plugin:@typescript-eslint/all

For details about how to configure Code Linter check rules, see Code Linter.