split-string
split-string copied to clipboard
RegExp separator
I think it would be useful if split-string would, like String.prototype.split, support splitting using a RegExp as the separator. One example where this is useful is with multiple separators in series which yield empty strings:
require('split-string')('foo bar', {separator: ' '})
// => [ 'foo', '', 'bar' ]
'foo bar'.split(' ')
// => [ 'foo', '', 'bar' ]
But with String.prototype.split's RegExp separator, one can split on one or more separator:
> 'foo bar'.split(/ +/)
// => [ 'foo', 'bar' ]