splitsplit / pattern /, string , [ limit ]
Scans a
string
for delimiters that match
pattern
, and
splits the string into a list of substrings, returning the resulting
list value in list context, or the count of substrings in scalar
context. The delimiters are determined by repeated pattern matching,
using the regular expression given in
pattern
, so the delimiters
may be of any size, and need not be the same string on every match.
If the
pattern
doesn't match at all,
If
limit
is specified and is not negative, the function splits into no
more than that many fields.
If
limit
is negative, it is
treated as if an arbitrarily large
limit
has
been specified. If
limit
is omitted, trailing null
fields are stripped from the result (which potential users of
If the pattern contains parentheses, then the substring matched by each pair of parentheses is included in the resulting list, interspersed with the fields that are ordinarily returned. Here's a simple case: that produces the list value:split /([-,])/, "1-10,20"; (1, '-', 10, ',', 20) |
|