How to split a string with multiple separators in Node.js

1 Answer

0 votes
const input = "abcdefg;hijk|lmno,pq_rst-uvwxyz";

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

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


 

/*
run:
  
abcdefg
hijk
lmno
pq
rst
uvwxyz
     
*/

 



answered Jul 21 by avibootz
...