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
Step 1: Add a Set Variable Step
In your flow, click Add Step and choose Set variables.
Add a new variable. Name it appropriately (e.g., phone_regex).
Step 2: Select the Input Variable to Evaluate
In the Set Variable step, select the value as an variable which points to the actual input value you are validating.
Then, click to select the variable that holds the input you want to test.
A modal will open with all the possibile variable modifiers available to you. Select the edit JSONata expression.
Step 3: Use a JSONata Expression for Regex
In the JSONata editor modal, paste your expression. For example, to validate a phone number:
$boolean($match($, /^(?:\+?[0-9] ?){6,14}[0-9]$/))
This expression checks if the input:
Is made up of 6 to 14 digits
May begin with a +
Allows optional spaces
Last digit is not a space
Then click Save.
Step 4: Test Your Expression
Click Run test in the Set Variable step.
Check the output section:
If it matches, you’ll see: "phone_regex": true
If it doesn’t match, you'll see: "phone_regex": false
Step 5: Use the Output in a Conditional Step
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
If phone_regex is false → Handle invalid input
Example Use Cases with JSONata Expressions
1. Email Validation
$boolean($match($, /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/))
Use this to ensure an email format is valid.
2. Zip Code Check (U.S.)
$boolean($match($, /^\d{5}(-\d{4})?$/))
Matches 12345 or 12345-6789.
3. Alphanumeric Code
$boolean($match($, /^[A-Za-z0-9]+$/))
Validates a string that must contain only letters and numbers.
Starts with a Specific Prefix
$boolean($match($, /^ABC/))
Returns true if the string starts with ABC.
Last updated
Was this helpful?