# 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="https://3861485111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU9kiDiTGVD8kkbnKKyEn%2Fuploads%2FfUSxR4o9SWl9OCFv4XUk%2F0.png?alt=media" 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="https://3861485111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU9kiDiTGVD8kkbnKKyEn%2Fuploads%2FeNiJeOkreSwc3KUKlJFE%2F1.png?alt=media" 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="https://3861485111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU9kiDiTGVD8kkbnKKyEn%2Fuploads%2FCwUS67FiVqWCxeeXcbeJ%2F2.png?alt=media" 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="https://3861485111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU9kiDiTGVD8kkbnKKyEn%2Fuploads%2FgFjvXEWOOjxaT8olPkaV%2F3.png?alt=media" 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

  ![](https://3861485111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU9kiDiTGVD8kkbnKKyEn%2Fuploads%2FizI7Zv1QGX9qh77Q6sHg%2F4.png?alt=media)

### **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.
