regexUnusedFlags
Reports regular expression flags that have no effect on the pattern.
✅ This rule is included in the ts logical presets.
Reports regular expression flags that have no effect on the pattern. Unused flags add unnecessary complexity and may mislead readers about the regex’s behavior.
Examples
Section titled “Examples”Unused i Flag (ignoreCase)
Section titled “Unused i Flag (ignoreCase)”The i flag is useless when the pattern contains no ASCII letters (A-Za-z).
const const pattern: RegExp
pattern = /123/i;const const digits: RegExp
digits = /\d+/i;const const pattern: RegExp
pattern = /abc/i;const const alphanumeric: RegExp
alphanumeric = /[a-z0-9]+/i;Unused m Flag (multiline)
Section titled “Unused m Flag (multiline)”The m flag is useless when the pattern contains no ^ or $ anchors.
const const pattern: RegExp
pattern = /abc/m;const const whitespace: RegExp
whitespace = /\s+/m;const const pattern: RegExp
pattern = /^abc/m;const const lineEnd: RegExp
lineEnd = /foo$/m;Unused s Flag (dotAll)
Section titled “Unused s Flag (dotAll)”The s flag is useless when the pattern contains no . metacharacters.
const const pattern: RegExp
pattern = /abc/s;const const escaped: RegExp
escaped = /a\.b/s;const const pattern: RegExp
pattern = /a.b/s;const const multiline: RegExp
multiline = /.*content.*/s;Multiple Unused Flags
Section titled “Multiple Unused Flags”const const pattern: RegExp
pattern = /123/ims;const const pattern: RegExp
pattern = /123/;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you add flags preemptively to patterns you intend to extend later, you might want to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
regexp/no-useless-flag
Made with ❤️🔥 around the world by
the Flint team and contributors.