# Split Text

> Cut one piece of text wherever a character appears, and take the piece you want or all of them.

Split Text cuts one piece of text wherever a character you choose appears, then hands back either one piece or the whole list.

> Dock: Data · Convert · Takes: text · Returns: one piece or a list of pieces

Use it when something arrives as one line, like `"enterprise, b2b, high-priority"`, and you need the parts separately. Or when you want one piece out of the middle: the domain from an email address, the surname from a full name.

> **Quick extractions without an extra step:** If you only need a single slice or quick domain/list split, you can do it directly inside field tokens with [Data Transformation](/build/core-concepts/data-transformation):
> - Domain from email: `{{ 2.email | extract_domain }}`
> - Surname: `{{ 2.name | after:" " }}`
> - Split to list: `{{ 2.tags | split:comma_space }}`
>
> Use the **Split Text** step when you need to pass an entire list of pieces to downstream canvas steps (like a [Loop](/build/action-steps/loops)).

**Keyboard shortcut:** `t+s`

## Setting it up

Three fields, all required.

### Input

The text you want to cut. Pick it from an earlier step with the data picker.

### Separator

The character or word to cut on. A comma, a single space, `\n` for line breaks.

It also accepts a **regular expression**, which is a pattern language for matching text. That is worth reaching for when the separator varies: a comma that sometimes has a space after it, say. If you do not write patterns, a plain character covers most cases.

### Segment Index

**Which piece you want back.** This is the field that decides whether you get one piece or all of them:

| Choose             | You get                               |
| ------------------ | ------------------------------------- |
| **First**          | Everything before the first separator |
| **Second**         | The second piece                      |
| **Last**           | Everything after the final separator  |
| **Second to Last** | The piece before the last one         |
| **All**            | Every piece, as a list                |

You can also type a number instead: `3` takes the third piece, `-2` counts back from the end.

> **Pick All when you want to loop over the pieces.** The named options each
> return a single piece of text, which is what you want for "the domain" or "the
> surname". For "do something with each tag", choose **All** and point a looping
> step at the result.

## What it passes on

The piece you asked for (or, with **All**, the list of pieces), nested under `ret`:

```
{{ 4.ret }}
```

Run it once and read the step's **Executions** tab for the exact shape before you build on it; that is quicker than reasoning it out.

## Examples to copy

### Every tag from one field

A CRM sends a contact's tags as `"enterprise, b2b, high-priority"` and you want to act on each.

| Field             | Value               |
| ----------------- | ------------------- |
| **Input**         | the tags field      |
| **Separator**     | `, ` (comma, space) |
| **Segment Index** | All                 |

Cutting on comma-and-space rather than the comma alone keeps a leading space off every piece after the first. `" b2b"` and `"b2b"` are different text, and a later [Filter](/build/action-steps/filter-items) matching on `b2b` would miss the first form.

Then turn on **Run for each item** on the next step and point it at this one. See [Loops & Iteration](/build/action-steps/loops).

### A surname from a full name

A form gives you `"Jane Doe"` and the greeting needs the surname.

| Field             | Value       |
| ----------------- | ----------- |
| **Input**         | `full_name` |
| **Separator**     | a space     |
| **Segment Index** | Last        |

**Last** rather than **Second**, so a double-barrelled surname or a middle name does not break it.

### The domain from an email address

| Field             | Value       |
| ----------------- | ----------- |
| **Input**         | the address |
| **Separator**     | `@`         |
| **Segment Index** | Last        |

Useful in front of a [Conditions](/build/action-steps/conditions) step that routes by company.

## What's Next?

- Do something with each piece using [Loops & Iteration](/build/action-steps/loops).
- Cut the list down before you act on it with [Filter](/build/action-steps/filter-items).
