How to make global backslash replacement in string in javascript

I tried: (If all the slashes make it difficult to read, the 1st line should replace the slashes, the second line should replace the backslash, the 3rd line should replace the asterisks.

newbigbend = bb_val.replace(/\//gi,"");
newbigbend = bb_val.replace(/\\/gi,"");
newbigbend = bb_val.replace(/*/gi,"");

to replace all slashes, backslashes, and asterisks. But when the browser hits the middle line newbigbend = bb_val.replace(/\\/gi,"");, it considers its inexhaustible comment. I know to use escape to replace the slash. Not sure you'll be back.

+3
source share
2 answers

, . newbigbend , .

, , :

newbigbend = bb_val.replace(/[/\\*]/g, "");

, i, . ( , [] / *, .) .

, - , newbigbend ( , Andrew):

newbigbend = bb_val.replace(/\//gi,"");
newbigbend = newbigbend.replace(/\\/gi,"");
newbigbend = newbigbend.replace(/\*/gi,"");
+6

*

newbigbend = bb_val.replace(/\*/gi,"");
+1

All Articles