Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


eslint-plugin-regexp is ESLint plugin for finding RegExp mistakes and RegExp style guide violations.

NPM license NPM version NPM downloads NPM downloads NPM downloads NPM downloads NPM downloads Build Status Coverage Status

πŸ“› Features

This ESLint plugin provides linting rules relate to better ways to help you avoid problems when using RegExp.

  • Find the wrong usage of regular expressions, and their hints.
  • Enforces a consistent style of regular expressions.
  • Find hints for writing optimized regular expressions.
  • 80 plugin rules for regular expression syntax and features.

You can check on the Online DEMO.

πŸ“– Documentation

See documents.

πŸ’Ώ Installation

npm install --save-dev eslint eslint-plugin-regexp


  • ESLint v8.44.0 and above
  • Node.js v18.x, v20.x and above

πŸ“– Usage

Add regexp to the plugins section of your .eslintrc configuration file (you can omit the eslint-plugin- prefix) and either use one of the two configurations available (recommended or all) or configure the rules you want:

The recommended configuration

The plugin:regexp/recommended config enables a subset of the rules that should be most useful to most users. See lib/configs/recommended.ts for more details.

// .eslintrc.js
module.exports = {
    "plugins": [
    "extends": [
         // add more generic rulesets here, such as:
         // 'eslint:recommended',

Advanced Configuration

Override/add specific rules configurations. See also:

// .eslintrc.js
module.exports = {
    "plugins": [
    "rules": {
        // Override/add rules settings here, such as:
        "regexp/rule-name": "error"

Using "plugin:regexp/all"

The plugin:regexp/all config enables all rules. It's meant for testing, not for production use because it changes with every minor and major version of the plugin. Use it at your own risk. See lib/configs/all.ts for more details.

βœ… Rules

πŸ’Ό Configurations enabled in.
⚠️ Configurations set to warn in.
βœ… Set in the plugin:regexp/recommended configuration.
πŸ”§ Automatically fixable by the --fix CLI option.
πŸ’‘ Manually fixable by editor suggestions.

Possible Errors

NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  Description πŸ’Ό ⚠️ πŸ”§ πŸ’‘
no-contradiction-with-assertion disallow elements that contradict assertions βœ… πŸ’‘
no-control-character disallow control characters πŸ’‘
no-dupe-disjunctions disallow duplicate disjunctions βœ… πŸ’‘
no-empty-alternative disallow alternatives without elements βœ… πŸ’‘
no-empty-capturing-group disallow capturing group that captures empty. βœ…
no-empty-character-class disallow character classes that match no characters βœ…
no-empty-group disallow empty group βœ…
no-empty-lookarounds-assertion disallow empty lookahead assertion or empty lookbehind assertion βœ…
no-escape-backspace disallow escape backspace ([\b]) βœ… πŸ’‘
no-invalid-regexp disallow invalid regular expression strings in RegExp constructors βœ…
no-lazy-ends disallow lazy quantifiers at the end of an expression βœ… πŸ’‘
no-misleading-capturing-group disallow capturing groups that do not behave as one would expect βœ… πŸ’‘
no-misleading-unicode-character disallow multi-code-point characters in character classes and quantifiers βœ… πŸ”§ πŸ’‘
no-missing-g-flag disallow missing g flag in patterns used in String#matchAll and String#replaceAll βœ… πŸ”§
no-optional-assertion disallow optional assertions βœ…
no-potentially-useless-backreference disallow backreferences that reference a group that might not be matched βœ…
no-super-linear-backtracking disallow exponential and polynomial backtracking βœ… πŸ”§
no-super-linear-move disallow quantifiers that cause quadratic moves
no-useless-assertions disallow assertions that are known to always accept (or reject) βœ… πŸ’‘
no-useless-backreference disallow useless backreferences in regular expressions βœ…
no-useless-dollar-replacements disallow useless $ replacements in replacement string βœ…
strict disallow not strictly valid regular expressions βœ… πŸ”§ πŸ’‘

Best Practices

NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  Description πŸ’Ό ⚠️ πŸ”§ πŸ’‘
confusing-quantifier disallow confusing quantifiers βœ…
control-character-escape enforce consistent escaping of control characters βœ… πŸ”§
negation enforce use of escapes on negation βœ… πŸ”§
no-dupe-characters-character-class disallow duplicate characters in the RegExp character class βœ… πŸ”§
no-empty-string-literal disallow empty string literals in character classes βœ…
no-extra-lookaround-assertions disallow unnecessary nested lookaround assertions βœ… πŸ”§
no-invisible-character disallow invisible raw character βœ… πŸ”§
no-legacy-features disallow legacy RegExp features βœ…
no-non-standard-flag disallow non-standard flags βœ…
no-obscure-range disallow obscure character ranges βœ…
no-octal disallow octal escape sequence πŸ’‘
no-standalone-backslash disallow standalone backslashes (\)
no-trivially-nested-assertion disallow trivially nested assertions βœ… πŸ”§
no-trivially-nested-quantifier disallow nested quantifiers that can be rewritten as one quantifier βœ… πŸ”§
no-unused-capturing-group disallow unused capturing group βœ… πŸ”§ πŸ’‘
no-useless-character-class disallow character class with one character βœ… πŸ”§
no-useless-flag disallow unnecessary regex flags βœ… πŸ”§
no-useless-lazy disallow unnecessarily non-greedy quantifiers βœ… πŸ”§
no-useless-quantifier disallow quantifiers that can be removed βœ… πŸ”§ πŸ’‘
no-useless-range disallow unnecessary character ranges βœ… πŸ”§
no-useless-set-operand disallow unnecessary elements in expression character classes βœ… πŸ”§
no-useless-string-literal disallow string disjunction of single characters in \q{...} βœ… πŸ”§
no-useless-two-nums-quantifier disallow unnecessary {n,m} quantifier βœ… πŸ”§
no-zero-quantifier disallow quantifiers with a maximum of zero βœ… πŸ’‘
optimal-lookaround-quantifier disallow the alternatives of lookarounds that end with a non-constant quantifier βœ… πŸ’‘
optimal-quantifier-concatenation require optimal quantifiers for concatenated quantifiers βœ… πŸ”§
prefer-escape-replacement-dollar-char enforces escape of replacement $ character ($$).
prefer-predefined-assertion prefer predefined assertion over equivalent lookarounds βœ… πŸ”§
prefer-quantifier enforce using quantifier πŸ”§
prefer-range enforce using character class range βœ… πŸ”§
prefer-regexp-exec enforce that RegExp#exec is used instead of String#match if no global flag is provided
prefer-regexp-test enforce that RegExp#test is used instead of String#match and RegExp#exec πŸ”§
prefer-set-operation prefer character class set operations instead of lookarounds βœ… πŸ”§
require-unicode-regexp enforce the use of the u flag πŸ”§
require-unicode-sets-regexp enforce the use of the v flag πŸ”§
simplify-set-operations require simplify set operations βœ… πŸ”§
sort-alternatives sort alternatives if order doesn't matter πŸ”§
use-ignore-case use the i flag if it simplifies the pattern βœ… πŸ”§

Stylistic Issues

NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  Description πŸ’Ό ⚠️ πŸ”§ πŸ’‘
grapheme-string-literal enforce single grapheme in string literal
hexadecimal-escape enforce consistent usage of hexadecimal escape πŸ”§
letter-case enforce into your favorite case πŸ”§
match-any enforce match any character style βœ… πŸ”§
no-useless-escape disallow unnecessary escape characters in RegExp βœ… πŸ”§
no-useless-non-capturing-group disallow unnecessary non-capturing group βœ… πŸ”§
prefer-character-class enforce using character class βœ… πŸ”§
prefer-d enforce using \d βœ… πŸ”§
prefer-lookaround prefer lookarounds over capturing group that do not replace πŸ”§
prefer-named-backreference enforce using named backreferences πŸ”§
prefer-named-capture-group enforce using named capture groups
prefer-named-replacement enforce using named replacement πŸ”§
prefer-plus-quantifier enforce using + quantifier βœ… πŸ”§
prefer-question-quantifier enforce using ? quantifier βœ… πŸ”§
prefer-result-array-groups enforce using result array groups πŸ”§
prefer-star-quantifier enforce using * quantifier βœ… πŸ”§
prefer-unicode-codepoint-escapes enforce use of unicode codepoint escapes βœ… πŸ”§
prefer-w enforce using \w βœ… πŸ”§
sort-character-class-elements enforces elements order in character class πŸ”§
sort-flags require regex flags to be sorted βœ… πŸ”§
unicode-escape enforce consistent usage of unicode escape or unicode codepoint escape πŸ”§


  • β›” These rules have been removed in a previous major release, after they have been deprecated for a while.
Rule ID Replaced by Removed in version
no-assertion-capturing-group regexp/no-empty-capturing-group v2.0.0
no-useless-exactly-quantifier regexp/no-useless-quantifier, regexp/no-zero-quantifier v2.0.0
no-useless-non-greedy regexp/no-useless-lazy v2.0.0
order-in-character-class regexp/sort-character-class-elements v2.0.0
prefer-t regexp/control-character-escape v2.0.0

βš™οΈ Settings

See Settings.

πŸš₯ Semantic Versioning Policy

eslint-plugin-regexp follows Semantic Versioning and ESLint's Semantic Versioning Policy.

🍻 Contributing

Welcome contributing!

Please use GitHub's Issues/PRs.


Development Tools

  • npm test runs tests and measures coverage.
  • npm run update runs in order to update readme and recommended configuration.
  • npm run new [new rule name] runs to create the files needed for the new rule.
  • npm run docs:watch starts the website locally.

πŸ”’ License

See the LICENSE file for license rights and limitations (MIT).