@tpmjs/official-regex-extract
Extract all regex matches from text with optional capture group support
Test @tpmjs/official-regex-extract (regexExtractTool) with AI-powered execution
0/2000 characters
Install this tool and use it with the AI SDK
npm install @tpmjs/official-regex-extractpnpm add @tpmjs/official-regex-extractyarn add @tpmjs/official-regex-extractbun add @tpmjs/official-regex-extractdeno add npm:@tpmjs/official-regex-extractimport { regexExtractTool } from '@tpmjs/official-regex-extract';import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { regexExtractTool } from '@tpmjs/official-regex-extract';
const result = await generateText({
model: openai('gpt-4o'),
tools: { regexExtractTool },
prompt: 'Your prompt here...',
});
console.log(result.text);(text: string, pattern: string, flags?: string, groups?: boolean) => Promise<unknown>Available configuration options
textstringThe text to search
patternstringRegular expression pattern
flagsstringRegular expression flags (g, i, m, s, u, y)
groupsbooleanReturn capture groups as objects
Schema extracted: 3/1/2026, 4:28:23 AM
Extract all regex matches from text with optional capture group support.
npm install @tpmjs/official-regex-extract
import { regexExtractTool } from '@tpmjs/official-regex-extract'; import { generateText } from 'ai'; const result = await generateText({ model: yourModel, tools: { regexExtract: regexExtractTool, }, prompt: 'Extract all email addresses from the text', });
text (string, required): The text to search for matchespattern (string, required): Regular expression pattern (without delimiters)flags (string, optional): Regular expression flags
g - global (automatically added if not present)i - case-insensitivem - multilines - dotAll (. matches newlines)u - unicodey - stickygroups (boolean, optional): If true, return detailed match objects with capture groups and positions. Default: false{ matches: string[] | MatchWithGroups[]; // Array of matches matchCount: number; // Total number of matches hasMatches: boolean; // Whether any matches were found } // When groups=true, each match is: { match: string; // The full matched text groups: Record<string, string>; // Named capture groups index: number; // Position in text }
const result = await regexExtractTool.execute({ text: 'Contact us at support@example.com or sales@example.com', pattern: '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}', flags: 'i', }); // { // matches: ['support@example.com', 'sales@example.com'], // matchCount: 2, // hasMatches: true // }
const result = await regexExtractTool.execute({ text: 'Visit https://example.com and http://test.org', pattern: '(?<protocol>https?)://(?<domain>[^\\s]+)', groups: true, }); // { // matches: [ // { // match: 'https://example.com', // groups: { protocol: 'https', domain: 'example.com' }, // index: 6 // }, // { // match: 'http://test.org', // groups: { protocol: 'http', domain: 'test.org' }, // index: 30 // } // ], // matchCount: 2, // hasMatches: true // }
const result = await regexExtractTool.execute({ text: 'Call (555) 123-4567 or (555) 987-6543', pattern: '\\(\\d{3}\\)\\s\\d{3}-\\d{4}', }); // { // matches: ['(555) 123-4567', '(555) 987-6543'], // matchCount: 2, // hasMatches: true // }
const result = await regexExtractTool.execute({ text: 'Love #JavaScript and #TypeScript!', pattern: '#\\w+', flags: 'i', }); // { // matches: ['#JavaScript', '#TypeScript'], // matchCount: 2, // hasMatches: true // }
const result = await regexExtractTool.execute({ text: 'Event on 2024-03-15 and deadline 2024-06-30', pattern: '(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})', groups: true, }); // { // matches: [ // { // match: '2024-03-15', // groups: { year: '2024', month: '03', day: '15' }, // index: 9 // }, // { // match: '2024-06-30', // groups: { year: '2024', month: '06', day: '30' }, // index: 33 // } // ], // matchCount: 2, // hasMatches: true // }
g (global) flag is automatically added to find all matches(?<name>...) for clearer results when groups=true\ ^ $ . * + ? ( ) [ ] { } |i flag for case-insensitive matchingm flag when matching across multiple lines with ^ and $The tool throws an error if:
MIT
Downloads/month
131
GitHub Stars
0
Quality Score