RosettaCodeData/Task/Multisplit/JavaScript/multisplit-1.js

9 lines
270 B
JavaScript
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
RegExp.escape = function(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
multisplit = function(string, seps) {
var sep_regex = RegExp(_.map(seps, function(sep) { return RegExp.escape(sep); }).join('|'));
return string.split(sep_regex);
}