How to Match Regex in Flows
Last updated
Was this helpful?
Last updated
Was this helpful?
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.
In your flow, click Add Step and choose Set variables.
Add a new variable. Name it appropriately (e.g., phone_regex).
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.
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.
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
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
Use this to ensure an email format is valid.
$boolean($match($, /^\d{5}(-\d{4})?$/))
Matches 12345 or 12345-6789.
$boolean($match($, /^[A-Za-z0-9]+$/))
Validates a string that must contain only letters and numbers.
$boolean($match($, /^ABC/))
Returns true if the string starts with ABC.