Quick answer

A valid regular expression must have balanced brackets, valid escape sequences, and correct quantifier placement.

Regex Invalid Pattern

A valid regular expression must have balanced brackets, valid escape sequences, and correct quantifier placement. Invalid syntax causes the engine to throw or fail.

Common causes

How to fix

Examples

Bad

[a-z

Good

[a-z]+

FAQ

What does 'invalid regular expression' mean?
The pattern has a syntax error: unclosed group, bad escape, or invalid quantifier. Use a regex tester to get the exact message and position.
Can I use \s and \d in JavaScript regex?
Yes. \d is digits, \s is whitespace. Use a regex literal /\d+/ or new RegExp('\\d+').

Fix it now

Try in validator (prefill this example)

Related

All tools · Canonical