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 pattern = /123/i;const digits = /\d+/i;const pattern = /abc/i;const 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 pattern = /abc/m;const whitespace = /\s+/m;const pattern = /^abc/m;const 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 pattern = /abc/s;const escaped = /a\.b/s;const pattern = /a.b/s;const multiline = /.*content.*/s;Multiple Unused Flags
Section titled “Multiple Unused Flags”const pattern = /123/ims;const 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 ❤️🔥 in Boston by
Josh Goldberg and contributors.