javascript - Remove symbols by RegExp -


i need remove next symbols :

  • \

  • /

  • .

  • ?

  • :

and tried use next regexp :

var nouse = new regexp("\/|\\|\:|\?","g"); ... var name = fullname.replace(nouse,"g"); ... 

but falls error :

syntaxerror: invalid regular expression: `//|\|:|?/:` nothing repeat 

how can change regexp?

in regexp constructor, have double escape backslashes:

new regexp("/|\\\\|:|\\?|\\.","g"); 

and backslash has escaped. oh , didn't have period in regex.

otherwise, can use character class:

new regexp("[/\\\\:?.]","g"); 

or use construct:

var nouse = /[\/\\:?.]/g; 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -