Skip to content

regexp/prefer-lookaround

🔧 This rule is automatically fixable by the --fix CLI option.

prefer lookarounds over capturing group that do not replace

📖 Rule Details

This rule reports string replacement using capturing groups that can be replaced with lookaround assertions.

Now loading...

🔧 Options

json
{
  "regexp/prefer-lookaround": ["error", {
      "lookbehind": true,
      "strictTypes": true
  }]
}
{
  "regexp/prefer-lookaround": ["error", {
      "lookbehind": true,
      "strictTypes": true
  }]
}

lookbehind

This option controls whether this rule will suggest using lookbehinds. Default is true.

Safari is the last major browser that still does not support regex lookbehind assertions (as of December 2022). So if your code base targets Safari, you cannot use lookbehinds.

strictTypes

If true, strictly check the type of object to determine if the regex instance was used in replace() and replaceAll(). Default is true.

This option is always on when using TypeScript.

🚀 Version

This rule was introduced in eslint-plugin-regexp v1.2.0

🔍 Implementation