Agent skill · data analytics · affaan-m
regex-vs-llm-structured-text
Decision framework for parsing structured text (quizzes, forms, invoices, receipts, tables) with a hybrid regex-first pipeline — regex extraction handles 95%+ cheaply, a confidence scorer flags low-confidence items, and an LLM validator fixes only the edge cases. Use when choosing between regex and LLM for text extraction, building a cheap document parser, or optimizing extraction cost and accuracy.
Why this skill is useful
Provides a decision framework and implementation details for effectively combining regex and LLM for structured text parsing, which the AI wouldn't reliably generate on its own.
What it needs
About 3k tokens when loaded. Last updated 2026-08-06. 238,342 stars on the source repository.
What this skill does
Regex vs LLM for Structured Text Parsing A practical decision framework for parsing structured text (quizzes, forms, invoices, documents). The key insight: regex handles 95-98% of cases cheaply and deterministically. Reserve expensive LLM calls for the remaining edge cases. When to Activate Parsing structured text with repeating patterns (questions, forms, tables) Deciding between regex and LLM for text extraction Building hybrid pipelines that combine both approaches Optimizing cost/accuracy tradeoffs in text processing Decision Framework Architecture Pattern Implementation 1. Regex Parser (Handles the Majority) 2. Confidence Scoring Flag items that may need LLM review: 3. LLM Validator (Edge Cases Only) 4. Hybrid Pipeline Real-World Metrics From a production quiz parsing pipeline (410 items): Metric Value -------- ------- Regex success rate 98.0% Low confidence items 8 (2.0%) LLM calls needed ~5 Cost savings vs all-LLM ~95% Test coverage 93% Best Practices Start with regex — even imperfect regex gives you a baseline to improve Use confidence scoring to programmatically identify what needs LLM help Use the cheapest LLM for validation (Haiku-class models are sufficient) Never mutate parsed items — return new instances from cleaning/validation steps TDD works well for parsers — write tests for known patterns first, then edge cases Log metrics (regex success rate, LLM call count) to track pipeline health Anti-Patterns to Avoid Sending all text to an LLM when regex handles 95%+ of cases (expensive and slow) Using regex for free-form, highly variable text (LLM is better here) Skipping confidence scoring and hoping regex "just works" Mutating parsed objects during cleaning/validation steps Not testing edge cases (malformed input, missing fields, encoding issues) When to Use Quiz/exam question parsing Form data extraction Invoice/receipt processing Document structure parsing (headers, sections, tables) Any structured text with repeating patterns where cost matters
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills affaan-m/regex-vs-llm-structured-text--fdfa59