Match, extract, replace and split text using regular expressions. Supports named capture groups, multiline mode, and Unicode. Use to validate formats, extract structured data from free-form text, or perform pattern-based transformations.
Operations
Operation
Description
match
Match the pattern anchored at the start of the string.
search
Find the first occurrence of the pattern anywhere in the text.
find_all
Find all non-overlapping matches in the text (default operation).
replace
Replace matches with a replacement string. Supports backreferences: $1, $name.
split
Split the text into an array of substrings at each pattern match.
validate
Check whether the entire string matches the pattern. Returns is_valid.
Input Parameters
Parameter
Type
Description
textrequired
string
The input text to search or transform.
patternrequired
string
Regular expression pattern. Supports named groups with (?P<name>...) syntax.
Replacement string for the replace operation. Supports positional backreferences ($1) and named backreferences ($name).
flagsoptional
array
Array of flag strings: ignorecase, multiline, dotall, unicode, global. Default: ["global"].
max_matchesoptional
integer
Maximum number of matches to return for find_all. Default: 100.
Output Fields
Field
Type
Description
matches
array
Array of match objects. Each has: value (string), start (integer), end (integer), groups (array of positional captures), named_groups (object of named captures).
match_count
integer
Total number of matches found.
result
string
Output string for replace (text after substitution) and split (JSON-encoded array of parts).
is_valid
boolean
For validate: true if the entire text matches the pattern, false otherwise.
Discovery hint: Use this tool whenever an agent needs to validate input formats (email, phone, ISBN), extract structured data from logs or documents, sanitize text by replacing patterns, or split strings by complex delimiters.
PascalAI Usage
usestoolslib;
varRX := LoadTool('mcp-regex');
// Validate email address formatvarV := RX.Call(JsonObj([
'text', UserEmail,
'pattern', '^[^@]+@[^@]+\.[^@]+$',
'operation', 'validate'
]));
if notV['is_valid'] thenError('Invalid email address');
// Extract all URLs from an HTML documentvarLinks := RX.Call(JsonObj([
'text', HTML,
'pattern', 'https?://[^\s"<>]+',
'operation', 'find_all'
]));
for varMinLinks['matches'] doWriteln(M['value']);