简体   繁体   中英

How to split a string on substrings with set of characters in Javascript?

Is there a quite simple way to split a string on substrings with set of characters like without using Regexp ?

abcd..,,qqww..::ss       - input
.,:    - characters
abcd qqww ss   - substrings

I would appreciate any suggestions.

You can use .replace() to pass in the values you don't want present in the output.

var str = 'abcd..,,qqww..::ss ';
var newStr = str.replace(/[.,:]/g,''); // if you want to replace them with spaces, change '' to ' '
alert(newStr) // results in abcdqqwwss

https://jsfiddle.net/kdqtpcq9/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM