Skip to main content

Match Node

Match Node Screenshot

Overview

The Match Node is used to match a string input against a series of regular expressions. Each regular expression corresponds to an output of the node.

The node can be configured to either run the first matching output port, or to run all matching output ports. If no match is found, the Unmatched output port will be executed.

This node is useful for routing control flow based on the content of a string. For example, you can use the Match Node to check if a user's message contains certain keywords and route the conversation accordingly.

If the Value input is provided, it will be passed through the corresponding output port if a match is found. If the Value input is not provided, the Test input will be passed through the corresponding output port if a match is found.

Inputs

TitleData TypeDescriptionDefault ValueNotes
TeststringThe string to be tested against the regular expressions.(required)The input will be coerced into a string if it is not a string.
ValueanyThe value to be passed to the output port if a match is found.(optional)If not provided, the Test input will be used as the value.

Example 1: Route control flow based on AI input

  1. Create a Chat Node and set the Prompt to a question, such as:

    Would you like to hear about information about cats or dogs first? Please only pick one! I will give you information on both, I just want to know what you'd like to hear first.

  2. Create a Match Node and connect the Message output of the Chat Node to the Test input of the Match Node.
  3. In the body of the Match Node, set the regular expressions to cats and dogs.
  4. Add three pairs of If Nodes and Text Nodes. Connect the Case 1 output of the Match Node to the first If Node's If input, the Case 2 output of the Match Node to the second If Node's If input, and the Unmatched output of the Match Node to the third If Node's If input. Connect the text nodes to the If Nodes' Value inputs.
  5. The text of the three Text Nodes should be "You chose cats!", "You chose dogs!", and "Sorry, I didn't understand that. Please try again.", respectively.
  6. Run the graph. Depending on the AI's response, the corresponding If Node will be executed, with the text the AI selected

Match Node Example 1

Error Handling

The Match Node will error if the Test input is not provided. If no match is found for the input string, the Unmatched output port will be executed.

FAQ

Q: Can multiple cases match at once?

A: Yes, multiple cases can match at once. If multiple cases match, all of the corresponding output ports will be executed. This may become a toggleable option in the future, so that only the first matching case will be executed.

Q: Can I use the Match Node to match against numbers?

A: Yes, you can use the Match Node to match against numbers. However, the Test input will be coerced into a string for the matching.

Q: Can I use the Match Node to match against a list of strings?

A: Yes, you can use the Match Node to match against a list of strings. However, the Test input will be coerced into a string for the matching. The default coercion will put each string on its own line for testing against.

See Also