Match Block
Route control flow based on string matching against regular expressions
Overview
The Match Block is used to route control flow based on matching a string input against a series of regular expressions. Each regular expression corresponds to an output of the block. This block is particularly useful for directing workflow based on the content of a string, such as checking for specific keywords in a user’s message.
Key Features
- Match string input against multiple regular expressions
- Option to run either the first matching output or all matching outputs
- Fallback ‘Unmatched’ output for when no match is found
- Flexible value passing through matched outputs
Inputs
The value that will be tested against each of the cases. Non-string inputs will be coerced to strings.
The value passed through to the output port that matches. If unconnected, the test value will be passed through.
Outputs
The value (or test if value is unconnected) passed through if the test value matches the corresponding regex case. The number of these outputs is dynamic based on the number of configured cases. Each output is labeled with its corresponding regex pattern, or “Case N” if the pattern is empty.
The value (or test if value is unconnected) passed through if no regexes match. Will not run if any match is found.
Editor Settings
If enabled, only the first matching branch will be ran. If disabled, all matching cases will run.
The list of regular expressions to match against. Each case corresponds to an output port.
Example: Route control flow based on AI input
- Create a Chat Block with a prompt asking about preference for cats or dogs.
- Connect the Chat Block’s
Message
output to a Match Block’sTest
input. - Set up the Match Block with regex cases for “cats” and “dogs”.
- Create three pairs of If Blocks and Text Blocks for different outcomes.
- Connect the Match Block’s outputs to the corresponding If Blocks.
- Run the flow to see the routing based on the AI’s response.
Error Handling
The Match Block will error if the Test
input is not provided. If no match is found, the Unmatched
output will be executed.