home / skills / bdambrosio / cognitive_workbench / matches

matches skill

/src/tools_out/matches

This skill checks text against a pattern or substring using substring, regex, or exact match to return true or false.

npx playbooks add skill bdambrosio/cognitive_workbench --skill matches

Review the files below or copy the command above to add this skill to your agents.

Files (1)
Skill.md
1.8 KB
---
name: matches
description: Check if text matches regex pattern or contains substring
type: prompt_augmentation
examples:
  - '{"type":"if","condition":{"type":"tool_condition","tool":"matches","target":"$text","pattern":"error"},"then":[...]}'
---

# Contains Pattern

Check whether text contains a pattern or substring.

## Purpose

- Enable conditional logic based on content
- Pattern matching for flow control
- Content validation
- Simple filtering

## Input Format

Accepts a Note containing text to check.

## Parameters

**Required:**
- **pattern** - Text string or regex pattern to match

**Optional:**
- **match_type** - "substring" (default), "regex", or "exact"

## Output Format

Returns a Note containing:
- "true" if pattern found
- "false" if pattern not found

## Usage Examples

**Simple substring check:**
```json
{"type":"matches","target":"$text","pattern":"error","out":"$has_error"}
```

**Regex pattern match:**
```json
{"type":"matches","target":"$email","pattern":"^[a-z]+@example\\.com$","match_type":"regex","out":"$is_valid_email"}
```

**Exact match:**
```json
{"type":"matches","target":"$status","pattern":"complete","match_type":"exact","out":"$is_complete"}
```

## Match Types

- **substring**: Pattern appears anywhere in text (case-sensitive)
- **regex**: Full regex pattern matching
- **exact**: Entire text must exactly match pattern

## Guidelines

- Case-sensitive by default
- Returns boolean as text ("true"/"false")
- Use for conditional logic in plans
- Combine with other conditionals as needed

## Examples

**Substring (default):**
```
Text: "Error occurred in module X"
Pattern: "Error"
Result: true
```

**Regex:**
```
Text: "[email protected]"
Pattern: ".*@example\\.com$"
Result: true
```

**Exact:**
```
Text: "done"
Pattern: "done"
Result: true

Text: "almost done"
Pattern: "done"
Result: false
```

Overview

This skill checks whether a piece of text contains a substring, matches a regular expression, or exactly equals a pattern. It returns a Note with the text values "true" or "false" to indicate the result. Use it to drive conditional logic, validate content, or filter messages in automated plans.

How this skill works

Provide the text to inspect and a pattern string. Choose match_type as "substring" (default), "regex", or "exact". The skill performs a case-sensitive test by default and outputs a Note with "true" if the pattern matches or "false" otherwise. Regex mode uses the full regex provided; exact mode requires an identical string match.

When to use it

  • Gate workflow steps based on message content
  • Validate user input like emails or status fields
  • Filter logs or messages containing keywords
  • Trigger alerts when specific patterns appear
  • Combine with other skills for complex conditional flows

Best practices

  • Explicitly set match_type when behavior matters (regex vs substring vs exact)
  • Escape regex metacharacters when using literal strings in regex mode
  • Normalize text (lowercase/trim) beforehand if case-insensitive comparison is needed
  • Keep regex patterns simple and tested to avoid performance issues
  • Treat the output as string boolean values "true"/"false" when chaining conditions

Example use cases

  • Detect the word "error" in log entries to route failure handling
  • Verify an email matches company domain with a regex before creating accounts
  • Check a status field equals "complete" to progress a workflow
  • Filter incoming messages for specific campaign codes using substring checks
  • Combine with a conditional skill to run remediation when a security pattern appears

FAQ

Is matching case-sensitive?

Yes, comparisons are case-sensitive by default. Normalize input first if you need case-insensitive checks.

What does regex mode expect?

Regex mode expects a full regular expression. Escape special characters when providing literal patterns and test expressions before use.

What does the skill return?

The skill returns a Note containing the text "true" if the pattern matches or "false" if it does not.