SyntaxError: nothing to repeat

The JavaScript exception "nothing to repeat" or "invalid quantifier in regular expression" occurs when a assertion.

Message

SyntaxError: Invalid regular expression: /\b+/: Nothing to repeat (V8-based)
SyntaxError: Invalid regular expression: /(?=)+/u: Invalid quantifier (V8-based)
SyntaxError: nothing to repeat (Firefox)
SyntaxError: invalid quantifier in regular expression (Firefox)
SyntaxError: Invalid regular expression: nothing to repeat (Safari)

Error type

disjunction alternative, etc., cannot repeat anything. Assertions don't consume characters, so it also doesn't make sense to repeat them.

In lookahead assertions to be quantified. This is a deprecated syntax and you should not rely on it.

Examples

Invalid cases

js
/\b+/; / \b is a word boundary assertion, it doesn't consume characters
/(*hello*)/;

Valid cases

js
/b+/; / b is a character, it can be repeated
/(\*hello\*)/; / Escape the asterisks to match them literally

See also