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

Test
string
required

The value that will be tested against each of the cases. Non-string inputs will be coerced to strings.

Value
any

The value passed through to the output port that matches. If unconnected, the test value will be passed through.

Outputs

Case [i]
any

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.

Unmatched
any

The value (or test if value is unconnected) passed through if no regexes match. Will not run if any match is found.

Editor Settings

Exclusive
boolean
default:false

If enabled, only the first matching branch will be ran. If disabled, all matching cases will run.

Cases
string[]
default:["YES","NO"]

The list of regular expressions to match against. Each case corresponds to an output port.

Example: Route control flow based on AI input

  1. Create a Chat Block with a prompt asking about preference for cats or dogs.
  2. Connect the Chat Block’s Message output to a Match Block’s Test input.
  3. Set up the Match Block with regex cases for “cats” and “dogs”.
  4. Create three pairs of If Blocks and Text Blocks for different outcomes.
  5. Connect the Match Block’s outputs to the corresponding If Blocks.
  6. 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.

FAQ

See Also