How to split a string with multiple separators in JavaScript

1 Answer

0 votes
const input = "abc,defg;hijk|lmnop-qrst_uvwxyz";

// Match multiple separators: comma, semicolon, pipe, dash, underscore
const result = input.split(/[,\;\|\-_]/);

result.forEach(word => {
    console.log(word);
});



/*
run:

abc
defg
hijk
lmnop
qrst
uvwxyz

*/

 



answered Jul 21 by avibootz
...