Here are some examples of invalid regular expressions that can commonly occur and might be causing the error in your case too:
// ❌ Not properly escaping special characters /.**/ -> /.*\*/ // ❌ Using double plus signs after a word boundary /w++/ -> /w+/ // ❌ Starting a regex with a quantifier /?[a-z]/ -> /[a-z]?/ /+[a-z]/ -> /[a-z]+/
- Make sure you properly escape special characters with a backslash. In the first example, two asterisks are used after each other which invalidates the regex.
- Verify that you don't accidentally repeat special characters. In the second example, we wanted to use a word boundary, but there is an extra plus sign at the end of the expression that causes a "Nothing to repeat" error.
- Make sure you don't start your regular expression with a quantifier. In the third example, the quantifier should come only after the character class, not before. Again, this can cause the above error.
- Unlimited access to hundred of tutorials
- Access to exclusive interactive lessons
- Remove ads to learn without distractions