split
Function: split()
Splits a string where a separator occurs, returning a list of substrings.
Syntax
split(string, separator)
Argument | Type | Description |
---|---|---|
string | String | String to be split |
separator | Regular Expressions | Regular expression representing the breakpoints in string where the splits should occur |
To return an empty string, specify an empty or null-valued argument.
If the split function cannot split the string, for example because there is no separator, it returns a string rather than a single element array.
The separator is expressed as a regular expression. This means that you can use any pattern that can be expressed as a regular expression as a separator. But it also means that you must escape any special characters of regular expressions if you are using these as plain text (e.g. you must use "\\|" to use | as a separator). See examples below.
Examples
split("",",")
andsplit(_NULL,",")
both return [ ]
split("one,two,three",",")
returns ["one","two","three"]
split("one::two::three","::")
returns ["one","two","three"]
split("one::two::","::")
returns ["one","two",""]
split("::::","::")
returns ["","",""]
split("field1|field2|field3","\\|")
returns ["field1","field2","field3"]
split("abc,123"), ",")
returns the array ["abc","123"]
split("abc", ",")
returns the string "abc"
rather than the single element array ["abc"]
.
Retrieving parameters from a URL
split("https://app.phixflow.com/phixflow/api/1/action/MyApp/MyAPI/trigger?param1=100", "\\?").2
returns a string "param1=100".
The .2 selects the second array element. For multiple parameters delimited by an ampersand, a second split is required.
The following expression will split the string at any single digit between 0 and 9:
split("some text1more text3final text","[0-9]")
and returns ["some text","more text","final text"]