Back to top

ReQL command: split

Command syntax

string.split([separator, [max_splits]]) → array


Splits a string into substrings. Splits on whitespace when called with no arguments. When called with a separator, splits on that separator. When called with a separator and a maximum number of splits, splits on that separator at most max_splits times. (Can be called with null as the separator if you want to split on whitespace while still specifying max_splits.)

Mimics the behavior of Python’s string.split in edge cases, except for splitting on the empty string, which instead produces an array of single-character strings.

Example: Split on whitespace.

r.expr("foo  bar bax").split().run(conn, callback)


["foo", "bar", "bax"]

Example: Split the entries in a CSV file.

r.expr("12,37,,22,").split(",").run(conn, callback)


["12", "37", "", "22", ""]

Example: Split a string into characters.

r.expr("mlucy").split("").run(conn, callback)


["m", "l", "u", "c", "y"]

Example: Split the entries in a CSV file, but only at most 3 times.

r.expr("12,37,,22,").split(",", 3).run(conn, callback)


["12", "37", "", "22,"]

Example: Split on whitespace at most once (i.e. get the first word).

r.expr("foo  bar bax").split(null, 1).run(conn, callback)


["foo", "bar bax"]

Get more help

Couldn't find what you were looking for?