Get to know MDN better
The JavaScript exception "invalid regexp group" occurs when the sequence (? does not start a valid group syntax. Recognized group syntaxes that start with (? include:
(? followed by any other character would cause this error.
? is not an atom, so it does not make sense to appear at the start of a capturing group (? is a quantifier and should be placed after an atom). Maybe you want to match the ? character literally, in which case you should escape it with a backslash (\?). Maybe you remembered the regex syntax wrong, and you intend to use one of the recognized group syntaxes listed above. Maybe you are using a feature that is not supported by the current JavaScript engine.
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.