Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

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 aUnicode-aware regular expression pattern contains a raw bracket ({,},]) that is not part of aquantifier orcharacter 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 shouldescape the characters to match them literally.

If{ appears in a context that accepts aquantifier, 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

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

Valid cases

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

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp