> For the complete documentation index, see [llms.txt](https://docs.bird.com/applications/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bird.com/applications/automation/flows/how-to/how-to-match-regex-in-flows.md).

# How to Match Regex in Flows

In **Flows**, you can validate string patterns using **regex** (regular expressions), but through **JSONata expressions**, not directly in conditionals.

This guide walks you through how to use regex in a **Set Variable** step using a JSONata expression, test it, and use the result in a follow-up **conditional** step.

### **Step-by-Step: Matching Regex in Flows** <a href="#jrh2x7x83voy" id="jrh2x7x83voy"></a>

#### **Step 1: Add a Set Variable Step** <a href="#iqxat8m5sm6z" id="iqxat8m5sm6z"></a>

1. In your flow, click **Add Step** and choose **Set variables**.<br>
2. Add a new variable. Name it appropriately (e.g., phone\_regex).

#### **Step 2: Select the Input Variable to Evaluate** <a href="#id-60cuhuk8h9wv" id="id-60cuhuk8h9wv"></a>

1. In the **Set Variable** step, select the value as an variable which points to the actual input value you are validating.<br>
2. Then, click to **select the variable** that holds the input you want to test.\ <br>

   <figure><img src="/files/E12zqr4gcrKiilkxmapX" alt=""><figcaption></figcaption></figure>
3. A modal will open with all the possibile variable modifiers available to you. Select the edit JSONata expression.\ <br>

   <figure><img src="/files/yPJXtkqvBd9UEtOYOmb9" alt=""><figcaption></figcaption></figure>

#### **Step 3: Use a JSONata Expression for Regex** <a href="#szxctsrystgu" id="szxctsrystgu"></a>

In the JSONata editor modal, paste your expression. For example, to validate a phone number:

**$boolean($match($, /^(?:\\+?\[0-9] ?){6,14}\[0-9]$/))**<br>

<figure><img src="/files/PmKYUONbSq8fHeJAyoIm" alt=""><figcaption></figcaption></figure>

\
This expression checks if the input:

* Is made up of 6 to 14 digits<br>
* May begin with a +<br>
* Allows optional spaces<br>
* Last digit is not a space<br>

Then click **Save**.

#### **Step 4: Test Your Expression** <a href="#cni1g5ng46il" id="cni1g5ng46il"></a>

1. Click **Run test** in the Set Variable step.<br>
2. Check the output section:<br>
   * If it matches, you’ll see: "phone\_regex": true<br>
   * If it doesn’t match, you'll see: "phone\_regex": false

<figure><img src="/files/PMn6qV0R6kQfsdz3s5uk" alt=""><figcaption></figcaption></figure>

#### **Step 5: Use the Output in a Conditional Step** <a href="#gkzbjg22h7pc" id="gkzbjg22h7pc"></a>

Now that your regex match is stored in a boolean variable (e.g., phone\_regex), you can use this in a **Conditional** step to control the flow.

For example:

* **If phone\_regex is true** → Proceed to success path<br>
* **If phone\_regex is false** → Handle invalid input

  ![](/files/4iqkHYMBBgJJdO9wkJMc)

### **Example Use Cases with JSONata Expressions** <a href="#n9wzql56ossl" id="n9wzql56ossl"></a>

#### **1. Email Validation** <a href="#mtcth835afci" id="mtcth835afci"></a>

#### $boolean($match($, /^\[\w-\\.]+@(\[\w-]+\\.)+\[\w-]{2,4}$/)) <a href="#mtcth835afci" id="mtcth835afci"></a>

Use this to ensure an email format is valid.

#### **2. Zip Code Check (U.S.)** <a href="#jnstglytj9vs" id="jnstglytj9vs"></a>

$boolean($match($, /^\d{5}(-\d{4})?$/))

Matches 12345 or 12345-6789.

#### **3. Alphanumeric Code** <a href="#dlewxbvlep6w" id="dlewxbvlep6w"></a>

$boolean($match($, /^\[A-Za-z0-9]+$/))

Validates a string that must contain only letters and numbers.

#### **Starts with a Specific Prefix** <a href="#id-8j3ql3508q1j" id="id-8j3ql3508q1j"></a>

$boolean($match($, /^ABC/))

Returns true if the string starts with ABC.


---

# 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://docs.bird.com/applications/automation/flows/how-to/how-to-match-regex-in-flows.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.
