SyntaxError: numbers out of order in {} quantifier.
The JavaScript exception "numbers out of order in {} quantifier" occurs when a quantifier in a regular expression uses the {n,m}
syntax but m
is less than n
.
Message
SyntaxError: Invalid regular expression: /1{2,1}/: numbers out of order in {} quantifier (V8-based) SyntaxError: numbers out of order in {} quantifier. (Firefox) SyntaxError: Invalid regular expression: numbers out of order in {} quantifier (Safari)
Error type
What went wrong?
The {n,m}
syntax in a regular expression is used to specify that the preceding item is to be matched at least n
times, but not more than m
times. If m
is less than n
, the quantifier is nonsensical because, for example, a character cannot appear at least 2 times but not more than 1 time. Therefore, an error is thrown.
Examples
Invalid examples
js
/1{2,1}/;
Valid examples
js
/1{1,2}/;