[Solved] JavaScript RegExp error – Nothing to repeat [duplicate]


With no regard to whether the pattern is correct or not:

Instead of using:

var re = new RegExp("\+", "gmi");

use:

var re = /\+/gmi;

See MDN – Creating a regular expression.

If you are using the string constructor, you need to string-escape all backslashes:

var re = new RegExp("\\+", "gmi");

As already mentioned in the comments, parsing HTML with a regexp is not always a good idea, especially in the browser using JavaScript, since you are already in the context of a giant HTML parser.

2

solved JavaScript RegExp error – Nothing to repeat [duplicate]