split
Splits a string on every occurrence of a separator.
A separator at the start or end yields an empty leading or trailing element, a separator that never appears returns the input as a single element, and an empty separator returns the input one UTF-8 rune per element.
InputArgumentsReturns
Sourcestringstring[]stringBehaviors
- Coerces scalars to text
- A scalar value such as a number or a boolean is converted to its text form before matching, so
42is accepted as"42".
BasicSource
Splits the value on every occurrence of the separator.
Given
{"csv": "Alice,42,admin"}Template
{{ csv | split:',' }}Result
[
"Alice",
"42",
"admin"
]Empty separatorSource
Splits the value into one element per UTF-8 rune when the separator is empty.
Given
{"word": "café"}Template
{{ word | split:'' }}Result
[
"c",
"a",
"f",
"é"
]No matchSource
Returns the value as a single element when the separator never appears.
Given
{"value": "no-commas-here"}Template
{{ value | split:',' }}Result
[
"no-commas-here"
]TrailingSource
Yields an empty trailing element when the value ends with the separator.
Given
{"path": "a/b/"}Template
{{ path | split:'/' }}Result
[
"a",
"b",
""
]