Skip to content

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.

The i flag is useless when the pattern contains no ASCII letters (A-Za-z).

const pattern = /123/i;
const digits = /\d+/i;

The m flag is useless when the pattern contains no ^ or $ anchors.

const pattern = /abc/m;
const whitespace = /\s+/m;

The s flag is useless when the pattern contains no . metacharacters.

const pattern = /abc/s;
const escaped = /a\.b/s;
const pattern = /123/ims;

This rule is not configurable.

If you add flags preemptively to patterns you intend to extend later, you might want to disable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.