🎄 Get 50% off from our JavaScript course for the holidays! 🎄

How to Fix "Nothing to repeat" Errors in JavaScript

Ferenc Almasi • 2022 July 16 • 📖 2 min read

The "Uncaught SyntaxError: Invalid regular expression: Nothing to repeat" error occurs in JavaScript when your regular expression is not valid. In order to fix the error, locate where the error is originating from, and then verify that the regular expression that you are using is valid.

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]+/
Copied to clipboard!

As a general rule, "Nothing to repeat" errors occur in JavaScript, whenever you have an invalid regular expression in your code. If you would like to try to experiment with regex, I recommend using regexr.com where matches will be highlighted according to your expression. If you are looking for more resources on Regex, check out one of the resources below.


Share on
  • twitter
  • facebook
JavaScript Course Dashboard

Tired of looking for tutorials?

You are not alone. Webtips has more than 400 tutorials which would take roughly 75 hours to read.

Check out our interactive course to master JavaScript in less time.

Learn More


🎉 Thank you for subscribing to our newsletter. x