Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid regular expression: /(/: Unterminated group

Tags:

regex

I want to create a function that removes all unwanted characters from a text. That´s waht I came up with, but it doesn´t work:

var invalid = "^°\"§%()[]{}=\\?´`'#<>|,;.:-+_";

for (var n = 0; n < invalid.length; n++) 
{
   var r = new RegExp(invalid[n],"g");
   toCheck.replace(r,"");
} 
like image 920
user3700591 Avatar asked Nov 17 '14 19:11

user3700591


1 Answers

You don't need to loop through invalid characters. Just use regex like this:

var invalid = /[°"§%()\[\]{}=\\?´`'#<>|,;.:+_-]+/g;
var repl = toCheck.replace(invalid, "");
like image 167
anubhava Avatar answered Sep 27 '22 17:09

anubhava