How browsers word it
| Chrome and Node (V8) | Invalid regular expression: /(abc/: Unterminated group |
|---|---|
| Firefox | SyntaxError: unterminated parenthetical |
| Safari | SyntaxError: Invalid regular expression: missing ) |
Common causes
A group was never closed
A left parenthesis opens a group and every group needs its closing one.
Input
(abc
Regex Tester says
Invalid regular expression: /(abc/: Unterminated group
An extra right parenthesis
A closing parenthesis with no group to close is reported as unmatched.
Input
abc)
Regex Tester says
Invalid regular expression: /abc)/: Unmatched ')'
A square bracket was never closed
A character class has the same problem with its brackets.
Input
[a-z
Regex Tester says
Invalid regular expression: /[a-z/: Unterminated character class
How to fix it
- Count the opening and closing parentheses, and indent nested groups while you read.
- Escape a literal parenthesis or bracket with a backslash: \( and \).
- When you build the pattern from user input, escape the input first.
- Paste the pattern into the regex tester to see the exact error.