Function: string-split

string-split is a function alias for split-string, defined in subr.el.gz.

Signature

(string-split STRING &optional SEPARATORS OMIT-NULLS TRIM)

Documentation

Split STRING into substrings bounded by matches for SEPARATORS.

The beginning and end of STRING, and each match for SEPARATORS, are splitting points. The substrings matching SEPARATORS are removed, and the substrings between the splitting points are collected as a list, which is returned.

If SEPARATORS is non-nil, it should be a regular expression matching text that separates, but is not part of, the substrings. If nil it defaults to split-string-default-separators, normally "[ \\f\\t\\n\\r\\v]+", and OMIT-NULLS is forced to t.

If OMIT-NULLS is t, zero-length substrings are omitted from the list (so that for the default value of SEPARATORS leading and trailing whitespace are effectively trimmed). If nil, all zero-length substrings are retained, which correctly parses CSV format, for example.

If TRIM is non-nil, it should be a regular expression to match text to trim from the beginning and end of each substring. If trimming makes the substring empty, it is treated as null.

If you want to trim whitespace from the substrings, the reliably correct way is using TRIM. Making SEPARATORS match that whitespace gives incorrect results when there is whitespace at the start or end of STRING. If you see such calls to split-string, please fix them.

Note that the effect of (split-string STRING) is the same as
(split-string STRING split-string-default-separators t). In the rare
case that you wish to retain zero-length substrings when splitting on whitespace, use (split-string STRING split-string-default-separators).

Modifies the match data; use save-match-data if necessary.

Probably introduced at or before Emacs version 29.1.

Aliases

string-split