Skip to content

split_regex

Splits a string into substrings with a regex.

split_regex(x:string, pattern:string, [max:int], [reverse:bool]) -> list

The split_regex function splits the input string x into a list of substrings using the specified regular expression pattern. Optional arguments allow limiting the number of splits (max) and reversing the splitting direction (reverse).

The string to split.

The regular expression used for splitting.

The maximum number of splits to perform.

Defaults to 0, meaning no limit.

If true, splits from the end of the string.

Defaults to false.

from {xs: split_regex("a1b2c", r"\d")}
{xs: ["a", "b", "c", ""]}
from {xs: split_regex("a1b2c3", r"\d", max=1)}
{xs: ["a", "b2c3"]}

split, join