strsplit
split a string by a regular expression
Last updated 14 years ago .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install strsplit 
SYNC missed versions from official npm registry.

node-strsplit: split a string by a regular expression

strsplit(str, pattern[, limit])

Splits a string str into at most limit fields using the pattern pattern as a delimeter. The pattern may be either a string or a regular expression. The returned value is an array of fields.

If limit is unspecified or zero, any number of fields may be returned, and the behavior is exactly identical to str.split(pattern).

strsplit(str, pattern, limit) behaves just like str.split(pattern, limit), with one important exception: the string is split at most limit - 1 times, so the last returned element contains the contents of all subsequent fields. String.split truncates all such fields.

By comparison, here's String.split:

> 'alpha bravo charlie delta'.split(' ', 3)
[ 'alpha', 'bravo', 'charlie' ]

and here's strsplit:

> strsplit('alpha bravo charlie delta', ' ', 3)
[ 'alpha', 'bravo', 'charlie delta' ]

This is the behavior implemented by split in Perl, Java, and other environments.

Current Tags

  • 1.0.0                                ...           latest (14 years ago)

2 Versions

  • 1.0.0                                ...           14 years ago
  • 0.0.1                                ...           14 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |