Nodes
Match#
The Match node is a logic node that checks if a given string matches a specified pattern. It's useful when you need to validate or filter strings based on a particular format or regular expression.
Inputs#
match
(string, default: ""): The pattern to match against. This can be a regular expression or a simple string.string
(string, default: ""): The input string to check for a match.
Outputs#
result
(boolean): Returnstrue
if the input string matches the specified pattern,false
otherwise.
Configuration#
This node has no additional configuration options.
Usage#
- Connect a string value to the
match
input to specify the pattern you want to match. This can be a regular expression or a simple string. - Connect the string you want to check to the
string
input. - The
result
output will emittrue
if the input string matches the pattern,false
otherwise.
Example#
Let's say you have a spell that processes email addresses and you want to validate that the input is a properly formatted email address before proceeding. You can use the Match node to check the format.
- Create a Match node and connect a Constant node with the value
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}$
to thematch
input. This regular expression matches common email address formats. - Connect the string you want to validate to the
string
input of the Match node. - Connect the
result
output to a Filter node. The Filter node will only pass through the original string if it matches the email format.
Best Practices#
- Use regular expressions for more complex pattern matching. Simple string matching is useful for exact matches, but regular expressions allow for much more flexibility.
- Be mindful of case sensitivity. By default, string matching is case sensitive. Use regular expression flags like
/i
for case-insensitive matching.
Common Issues#
- Forgetting to escape special characters in regular expressions. Characters like
., +, *, ?
have special meaning in regular expressions and need to be escaped with a backslash\
to match them literally. - Overly complex regular expressions can be difficult to read and maintain. Use comments and break complex expressions into smaller parts for better readability.