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

9 lines
270 B
JavaScript
Raw Normal View History

2013-04-10 21:29:02 -07: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);
}