Skip to content

regexAmbiguousInvalidity

Reports regex patterns that use ambiguous or invalid syntax from Annex B.

✅ This rule is included in the ts logical and logicalStrict presets.

ECMAScript Annex B defines legacy regex syntax that browsers must support for web compatibility but is considered ambiguous or deprecated. This includes octal escapes in patterns, incomplete escape sequences, useless escapes, and unescaped special characters outside of character classes. Using strict regex syntax ensures better clarity and cross-platform compatibility.

When the u (unicode) or v (unicode sets) flag is present, JavaScript already enforces strict regex parsing, so this rule skips those patterns.

// Octal escapes in regex patterns
const
const re1: RegExp
re1
= /\1/;
const
const re2: RegExp
re2
= /\07/;
// Incomplete escape sequences
const
const re3: RegExp
re3
= /\x1/;
const
const re4: RegExp
re4
= /\u123/;
const
const re5: RegExp
re5
= /\c1/;
// Unescaped brackets outside character classes
const
const re6: RegExp
re6
= /a]/;
const
const re7: RegExp
re7
= /a{/;
// Useless escapes
const
const re8: RegExp
re8
= /\q/;
const
const re9: RegExp
re9
= /\!/;
// Same issues with RegExp constructor
const
const re10: RegExp
re10
= new
var RegExp: RegExpConstructor
new (pattern: RegExp | string, flags?: string) => RegExp (+2 overloads)
RegExp
("\\1");

This rule is not configurable.

If you are intentionally using legacy regex syntax for compatibility with very old JavaScript environments or specific regex behavior, you may choose to disable this rule. However, in modern development, using strict regex syntax is recommended.

Made with ❤️‍🔥 around the world by the Flint team and contributors.