Skip to content

split

The split function divides a string into an array of substrings using a specified delimiter. You can optionally retrieve a specific element from the resulting array by index.

{input | split:delimiter:index:fallback}
  • input (string): The string to split
  • delimiter (string): The character or string to split by
  • index (number, optional): Zero-based index of the element to return
  • fallback (string, optional): Default value if input is empty or index is out of bounds (defaults to “N/A”)
  • If index is provided: Returns the element at the specified index or the fallback value
  • If index is not provided: Returns the entire array of split elements
{"apple,banana,orange" | split:","}
// Returns: ["apple", "banana", "orange"]
{"apple,banana,orange" | split:",":1}
// Returns: "banana"
{"apple,banana" | split:",":5:"Not found"}
// Returns: "Not found"
{project.name | split:"-":2:"N/A"}
// Returns: The third segment of a hyphen-separated project name, or "N/A" if not found
{"192.168.1.1" | split:".":0}
// Returns: "192"
{file.path | split:"/":3:"Unknown"}
// Returns: The fourth segment of the path, or "Unknown" if not found