Reputation: 11
i need to split a string by semicolon, colon, comma, cr, lf, clfr and whitespace. How can i do that?
Upvotes: 1
Views: 6287
Reputation: 536
I would recommend /[,.;/ ]/
regex. It will split with all provided chars between []
"55,22.222;55 555".split(/[,.;/ ]/)
"15/01/2020".split(/[,.;/ ]/)
(Remove last empty space if you don't want to split by space => /[,.;/]/ )
Upvotes: 0
Reputation: 31602
You can give the split function a regex to split it by.
A simple one looks like this.
const text = "a,c;d e";
const splitted = text.split(/;|,| /);
Upvotes: 6