How browsers word it
| Chrome and Node (V8) | Invalid regular expression: /*abc/: Nothing to repeat |
|---|
Common causes
The pattern starts with a quantifier
Someone wrote a shell wildcard such as *.txt, where * means anything. In a regex it is a quantifier and needs something before it.
Input
*abc
Regex Tester says
Invalid regular expression: /*abc/: Nothing to repeat
Two quantifiers in a row
a** repeats a repeat. To make a repeat lazy, add ? after it (a*?), but nothing else may follow a quantifier directly.
Input
a**
Regex Tester says
Invalid regular expression: /a**/: Nothing to repeat
A quantifier after an anchor
^ and $ match positions, not characters, so they cannot be repeated.
Input
^*
Regex Tester says
Invalid regular expression: /^*/: Nothing to repeat
How to fix it
- For any characters use .* (dot, then star), not a bare *.
- Escape a literal quantifier character: \* or \+ or \?.
- Remove the doubled quantifier, or add ? only to make a repeat lazy.
- Paste the pattern into the regex tester: it reports the error as you type.