close

prefer-regexp-exec

Configuration

rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/prefer-regexp-exec': 'error',
    },
  },
]);

Rule Details

Prefer RegExp#exec over String#match when a non-global regex match is used.

Examples of incorrect code for this rule:

const value = 'foo';
value.match(/foo/);
value.match('foo');

Examples of correct code:

const value = 'foo';
/foo/.exec(value);
value.match(/foo/g);

Original Documentation