split-string icon indicating copy to clipboard operation
split-string copied to clipboard

RegExp separator

Open silverwind opened this issue 6 years ago • 0 comments

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' ]

silverwind avatar Dec 20 '18 15:12 silverwind