Reputation: 323
I have to write several lines of code to remove delimiters from a string. Is there a more efficient way to remove all delimiters? Thanks.
str = str.toLowerCase();
str = str.replace(/ /g,'');
str = str.replace(/\*/g, '');
str = str.replace(/_/g, '');
str = str.replace(/#/g, '');
//etc....
Upvotes: 0
Views: 3747
Reputation: 92854
Use character class:
str = str.toLowerCase().replace(/[ *_#]/g, '');
http://www.regular-expressions.info/charclass.html
Upvotes: 8