Skip to content

eslint/rules/regular-expressions ​

Regular expressions (core rules): The regular expression rules of ESLint, SonarJS and Unicorn; the regexp plugin has its own block. Rules of ESLint, typescript-eslint and SonarJS (the Sonar way profile of SonarQube) on this subject, every rule listed; the TypeScript rules apply to TypeScript files only.

32 rules, 23 on. Source: lint/eslint/rules/regular-expressions.mjs.

RuleSettingFilesWhat it checksWhy
no-control-regexerrorJS + TSDisallow control characters in regular expressions—
no-empty-character-classerrorJS + TSDisallow empty character classes in regular expressions—
no-invalid-regexperrorJS + TSDisallow invalid regular expression strings in RegExp constructors—
no-misleading-character-classerrorJS + TSDisallow characters which are made with multiple code points in character class syntax—
no-useless-backreferenceerrorJS + TSDisallow useless backreferences in regular expressions—
no-div-regexerrorJS + TSDisallow equal signs explicitly at the beginning of regular expressions—
no-regex-spaceserrorJS + TSDisallow multiple spaces in regular expressions—
prefer-named-capture-groupinfoJS + TSEnforce using named capture group in regular expression—
prefer-regex-literalsinfo, {"disallowRedundantWrapping":true}JS + TSDisallow use of the RegExp constructor in favor of regular expression literals—
require-unicode-regexpinfo, {"requireFlag":"v"}JS + TSEnforce the use of u or v flag on regular expressions—
sonarjs/no-control-regexoffJS + TSRegular expressions should not contain control charactersOff: duplicate of no-control-regex.
sonarjs/no-empty-character-classoffJS + TSEmpty character classes should not be usedOff: duplicate of no-empty-character-class.
sonarjs/no-invalid-regexpoffJS + TSRegular expressions should be syntactically validOff: duplicate of no-invalid-regexp.
sonarjs/no-misleading-character-classoffJS + TSUnicode Grapheme Clusters should be avoided inside regex character classesOff: duplicate of no-misleading-character-class.
sonarjs/no-regex-spacesoffJS + TSRegular expressions should not contain multiple spacesOff: duplicate of no-regex-spaces.
sonarjs/prefer-regexp-execoffJS + TS"RegExp.exec()" should be preferred over "String.match()"Off: duplicate of @typescript-eslint/prefer-regexp-exec.
sonarjs/anchor-precedenceerrorJS + TSAlternatives in regular expressions should be grouped when used with anchors—
sonarjs/comment-regexoffJS + TSTrack comments matching a regular expressionOff: not in the Sonar way profile of SonarQube.
sonarjs/concise-regexwarnJS + TSRegular expression quantifiers and character classes should be used concisely—
sonarjs/duplicates-in-character-classwarnJS + TSCharacter classes in regular expressions should not contain the same character twice—
sonarjs/existing-groupserrorJS + TSReplacement strings should reference existing regular expression groups—
sonarjs/no-empty-after-reluctantwarnJS + TSReluctant quantifiers in regular expressions should be followed by an expression that can't match the empty string—
sonarjs/no-empty-alternativeserrorJS + TSAlternation in regular expressions should not contain empty alternatives—
sonarjs/no-empty-groupwarnJS + TSRegular expressions should not contain empty groups—
sonarjs/regex-complexitywarnJS + TSRegular expressions should not be too complicated—
sonarjs/shorthand-property-groupingoffJS + TSShorthand object properties should be grouped at the beginning or end of an object declarationOff: not in the Sonar way profile of SonarQube.
sonarjs/single-char-in-character-classeswarnJS + TSCharacter classes in regular expressions should not contain only one character—
sonarjs/stateful-regexerrorJS + TSRegular expressions with the global flag should be used with caution—
sonarjs/super-linear-regexwarnJS + TSRegular expressions should not cause non-linear backtracking—
sonarjs/unicode-aware-regexoffJS + TSRegular expressions using Unicode character classes or property escapes should enable the unicode flagOff: not in the Sonar way profile of SonarQube.
sonarjs/unused-named-groupswarnJS + TSNames of regular expressions named groups should be used—
@typescript-eslint/prefer-regexp-execerrorTSEnforce RegExp#exec over String#match if no global flag is provided—

Generated from the JSDoc of the sources.