Version: v0.7.1 - Beta.  We welcome contributors & feedback.


split($stringOrRegex, $options = {}) -> list


Split into a list of substrings, on a string delimiter or regex pattern.

All elements will be trimmed of whitespace, and empty strings will be filtered out.

'a / b / c'.split('/')
//= ['a', 'b', 'c']

'/a/b/c/ /'.split('/')
//= ['a', 'b', 'c']

'a  b c '.split(R'\s+')
//= ['a', 'b', 'c']


Option Value Description
limit number Maximum number of returned elements. The last element will contain the rest of the string.
keepWhitespace true/false Do not automatically trim and filter empty elements.
'a/b/c/d/e'.split('/', { limit: 3 })
//= ['a', 'b', 'c/d/e']

'/a/b/ c / '.split('/', 0, -keepWhitespace)
//= ['', 'a', 'b', ' c ', ' ']

See Also