Skip to main content

SyntaxError: raw bracket is not allowed in regular expression with unicode flag

The JavaScript exception "raw bracket is not allowed in regular expression with unicode flag" occurs when a Unicode-aware regular expression pattern contains a raw bracket ({, }, ]) that is not part of a quantifier or character class.

Message

SyntaxError: Invalid regular expression: /{/u: Lone quantifier brackets (V8-based)
SyntaxError: raw bracket is not allowed in regular expression with unicode flag (Firefox)
SyntaxError: Invalid regular expression: incomplete {} quantifier for Unicode pattern (Safari)
SyntaxError: Invalid regular expression: unmatched ] or } bracket for Unicode pattern (Safari)

Error type

What went wrong?

In Unicode-unaware mode, {, }, and ] that are not part of a quantifier or character class are treated as literal characters. This may hide errors in your code and is therefore deprecated and disallowed in Unicode-aware mode. You should either check whether you have invalid syntax or you should escape the characters to match them literally.

If { appears in a context that accepts a quantifier, it is treated as the start of a quantifier. If what follows it is not a valid quantifier, another syntax error, incomplete quantifier, is thrown.

Examples

Invalid cases

/\{{MDN_Macro}}/u;
/\[sic]/u;

Valid cases

// All { and } need to be escaped
/\\{\\{MDN_Macro\\}\\}/u;
// The ] needs to be escaped
/\[sic\]/u;

See also