> For the complete documentation index, see [llms.txt](https://sevenval.gitbook.io/flat/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sevenval.gitbook.io/flat/reference/functions/split.md).

# split()

```
node-set split(string subject, [string pattern])
```

`split()` converts the "subject" string into a node-set of `<token>` elements. The optional pattern is a Perl-compatible regular expression (without delimiters). It is used to split the input string. If no pattern is given, the string is split at every block of whitespace characters (space, tab, newline).

Example without pattern:

```
split("A B C")
```

returns

```markup
<token>A</token>
<token>B</token>
<token>C</token>
```

Example with pattern

```
split("A:B : C", "\s*:\s*")
```

returns

```markup
<token>A</token>
<token>B</token>
<token>C</token>
```

The elements of the result node-set may be used with positional predicates:

```
split("A  B C")[2]
```

returns

```markup
<token>B</token>
```

> 📎 Note that empty token elements will be discarded.

For use in a [JSON template](/flat/reference/templating.md) with [`loop()`](/flat/reference/templating/loop.md), the resulting node-set has to be cast into an array with the [`array()` function](/flat/reference/functions/array.md):

```markup
<template>
[
  {{loop array(split("Alice.Bob.Eve", "\.")) }}
  {{.}}
  {{end}}
]
</template>
```

If necessary, in-place regex modifiers can be used with the `(?<modifier>)` syntax, where `<modifier>` can be

* `i`: case-insensitive match
* `m`: `^` and `$` match for every line in the subject ("multiline")
* `x`: ignore whitespace in pattern for readability ("extended")

Example with case-insensitive match of `x` and `X`:

```
split("AXBxC", "(?i)x")
```

returns

```markup
<token>A</token>
<token>B</token>
<token>C</token>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sevenval.gitbook.io/flat/reference/functions/split.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
