regex-extract Extract all matches of a regex pattern
Flags
--pattern string default:
Examples
Extract phone numbers from text
Usage
"Call 555-1234 or 555-5678
Fax: 555-0000" | regex-extract --pattern=\d{3}-\d{4} Extract hashtags from social media posts
Usage
"Trending now: #SummerSale #BigSavings #ShopNow
Check out #Ne..." | regex-extract --pattern=#\w+ Pull all dates from meeting notes
Usage
"Meeting on 2025-06-15, follow-up by 2025-06-22.
Deadline: 20..." | regex-extract --pattern=\d{4}-\d{2}-\d{2} View source
(input, opts = {})=>{
if (!opts.pattern) return "Error: provide --pattern";
try {
const re = new RegExp(opts.pattern, "gm");
const matches = [
...input.matchAll(re)
];
if (!matches.length) return "(no matches)";
return matches.map((m, i)=>`${i + 1}: ${m[0]}${m.length > 1 ? ` → groups: [${m.slice(1).join(", ")}]` : ""}`).join("\n");
} catch (e) {
return `Error: ${e.message}`;
}
}