Regular expressions
Regular-expression rules from eslint-plugin-regexp.
These rules check regex literal structure: emptiness, uselessness, flag ordering, shorthand classes, and Unicode support.
Some rules duplicate (and supersede) the regex-related rules in Core; both ids exist so projects can keep the legacy ESLint names alongside the regexp-plugin variants.
Source: eslint-plugin-regexp (MIT).
Rule index
Each rule name links to the detailed section below.
Examples come from the checked lint corpus or package-level rule tests when project layout matters.
regexp/no-control-character: Reject ASCII control characters in regex literals.regexp/no-dupe-characters-character-class: Reject duplicate literal characters inside simple regex character classes.regexp/no-empty-alternative: Reject empty alternatives in a disjunction.regexp/no-empty-capturing-group: Reject empty capturing groups such as/()/.regexp/no-empty-character-class: Reject empty regex character classes.regexp/no-empty-group: Reject empty non-capturing groups such as/(?:)/.regexp/no-empty-lookarounds-assertion: Reject empty lookaround assertions such as/(?=)/or/(?!)/.regexp/no-misleading-unicode-character: Reject misleading Unicode characters in regex classes.regexp/no-useless-character-class: Reject single-character character classes such as/[x]/,/x/is equivalent.regexp/no-useless-escape: Reject unnecessary escapes inside regex literals.regexp/no-useless-flag: Reject regex flags that the literal does not exercise,ion a pattern.regexp/no-useless-quantifier: Reject quantifiers that do not change the match, constant-one counts (/a{1}/).regexp/no-useless-two-nums-quantifier: Reject equal min/max quantifiers in favor of/a{2}/.regexp/no-zero-quantifier: Reject zero-repeat quantifiers , the atom never matches.regexp/prefer-d: Prefer\dover[0-9]in regex literals.regexp/prefer-plus-quantifier: Prefer+over{1,}in regex literals.regexp/prefer-question-quantifier: Prefer?over{0,1}in regex literals.regexp/prefer-star-quantifier: Prefer*over{0,}in regex literals.regexp/prefer-w: Prefer\wover[A-Za-z0-9_]in regex literals.regexp/require-unicode-regexp: Require regex literals to use theuorvflag.regexp/require-unicode-sets-regexp: Require regex literals to use thevflag specifically, the stricter Unicode-sets mode.regexp/sort-flags: Require regex flags to appear in canonical alphabetical order.
Rules
regexp/no-control-character
Reject ASCII control characters in regex literals. Alias of the bare core check.
Example:
// reports: regexp/no-control-character (error)
const control = /\x1f/;regexp/no-dupe-characters-character-class
Reject duplicate literal characters inside simple regex character classes (/[aa]/).
Example:
// reports: regexp/no-dupe-characters-character-class (error)
const duplicate = /[aba]/;regexp/no-empty-alternative
Reject empty alternatives in a disjunction (/a||b/), which silently match the empty string.
Example:
// reports: regexp/no-empty-alternative (error)
const emptyAlt = /a||b/;regexp/no-empty-capturing-group
Reject empty capturing groups such as /()/.
The group shifts the numbering of every later backreference and capture slot while only ever capturing the empty string, almost always a leftover from an unfinished edit.
Example:
// reports: regexp/no-empty-capturing-group (error)
const emptyCap = /()/;regexp/no-empty-character-class
Reject empty regex character classes ([]). Alias of the bare core check.
Example:
// reports: regexp/no-empty-character-class (error)
const empty = /[]/;regexp/no-empty-group
Reject empty non-capturing groups such as /(?:)/.
The group contributes nothing to the match and is virtually always a leftover from a deleted inner pattern.
Example:
// reports: regexp/no-empty-group (error)
const emptyGroup = /(?:)/;regexp/no-empty-lookarounds-assertion
Reject empty lookaround assertions such as /(?=)/ or /(?!)/.
An empty positive lookaround always matches; an empty negative lookaround never matches. The assertion either collapses to a no-op or breaks the surrounding pattern.
Example:
// reports: regexp/no-empty-lookarounds-assertion (error)
const emptyLook = /(?=)/;regexp/no-misleading-unicode-character
Reject misleading Unicode characters in regex classes. Alias of the bare misleading-character check.
Example:
// reports: regexp/no-misleading-unicode-character (error)
const unicode = /[👍]/;regexp/no-useless-character-class
Reject single-character character classes such as /[x]/, /x/ is equivalent.
Example:
// reports: regexp/no-useless-character-class (error)
const single = /[x]/;regexp/no-useless-escape
Reject unnecessary escapes inside regex literals. Alias of core no-useless-escape for regex contexts.
Example:
// reports: regexp/no-useless-escape (error)
const escape = /\a/;regexp/no-useless-flag
Reject regex flags that the literal does not exercise, i on a pattern without case-variable characters, m without ^/$, s without ., and similar dead flags on g/y.
Cleans up flag combos that suggest behavior the pattern can never trigger.
Example:
// reports: regexp/no-useless-flag (error)
const value = /\d+/i;regexp/no-useless-quantifier
Reject quantifiers that do not change the match, constant-one counts (/a{1}/), ? on patterns already matching the empty string (/(?:a+|b*)?/), and quantifiers on non-consuming atoms (/(?:\b)+/).
Example:
// reports: regexp/no-useless-quantifier (error)
const value = /a{1}/;regexp/no-useless-two-nums-quantifier
Reject equal min/max quantifiers (/a{2,2}/) in favor of /a{2}/.
Example:
// reports: regexp/no-useless-two-nums-quantifier (error)
const value = /a{2,2}/;regexp/no-zero-quantifier
Reject zero-repeat quantifiers (/a{0}/, /a{0,0}/), the atom never matches, so the quantifier is either dead code or a typo for {1,...}.
The fix is normally to delete the atom or correct the upper bound.
Example:
// reports: regexp/no-zero-quantifier (error)
const value = /a{0}/;regexp/prefer-d
Prefer \d over [0-9] in regex literals.
Example:
// reports: regexp/prefer-d (error)
const digit = /[0-9]/;regexp/prefer-plus-quantifier
Prefer + over {1,} in regex literals.
Example:
// reports: regexp/prefer-plus-quantifier (error)
const value = /a{1,}/;regexp/prefer-question-quantifier
Prefer ? over {0,1} in regex literals.
Example:
// reports: regexp/prefer-question-quantifier (error)
const value = /a{0,1}/;regexp/prefer-star-quantifier
Prefer * over {0,} in regex literals.
Example:
// reports: regexp/prefer-star-quantifier (error)
const value = /a{0,}/;regexp/prefer-w
Prefer \w over [A-Za-z0-9_] in regex literals.
Example:
// reports: regexp/prefer-w (error)
const word = /[A-Za-z0-9_]/;regexp/require-unicode-regexp
Require regex literals to use the u or v flag, so Unicode-property escapes and surrogate-pair handling stay predictable.
Example:
// reports: regexp/require-unicode-regexp (error)
const value = /a/;regexp/require-unicode-sets-regexp
Require regex literals to use the v flag specifically, the stricter Unicode-sets mode that enables set notation, string properties, and stricter escape rules on top of u.
Choose this over require-unicode-regexp only on engines that ship ES2024-era regex.
Example:
// reports: regexp/require-unicode-sets-regexp (error)
const value = /a/u;regexp/sort-flags
Require regex flags to appear in canonical alphabetical order (dgimsuvy).
Stable ordering keeps diffs small and lets readers compare flag sets at a glance.
Example:
// reports: regexp/sort-flags (error)
const value = /a/im;