SyntaxError: invalid regular expression flag "x"

이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 참여해서 번역을 마치도록 도와 주세요!
English (US)의 문서도 읽어보세요.


SyntaxError: invalid regular expression flag "x" (Firefox)
SyntaxError: Invalid regular expression flags (Chrome)

Error type


What went wrong?

There are invalid regular expression flags in the code. In a regular expression literal, which consists of a pattern enclosed between slashes, the flags are defined after the second flag. They can also be defined in the constructor function of the RegExp object (second parameter). Regular expression flags can be used separately or together in any order, but there are only five of them in ECMAScript.

To include a flag with the regular expression, use this syntax:

var re = /pattern/flags;


var re = new RegExp('pattern', 'flags');
Regular expression flags
Flag Description
g Global search.
i Case-insensitive search.
m Multi-line search.
u Unicode; treat pattern as a sequence of Unicode code points
y Perform a "sticky" search that matches starting at the current position in the target string. See sticky


There are only five valid regular expression flags.


// SyntaxError: invalid regular expression flag "b"

Did you intend to create a regular expression? An expression containing two slashes is interpreted as a regular expression literal.

let obj = {
  url: /docs/Web

// SyntaxError: invalid regular expression flag "W"

Or did you mean to create a string instead? Add single or double quotes to create a string literal.

let obj = {
  url: '/docs/Web'

Valid regular expression flags

See the table above for the five valid regular expression flags that are allowed in JavaScript.


See also

문서 태그 및 공헌자

 이 페이지의 공헌자: fscholz
 최종 변경: fscholz,