Skip to content
Back to skills

Regex Vs Llm

ASecurity

Decision framework and hybrid pattern for choosing between deterministic regex and LLM extraction. Handles 95%+ of structured text tasks with zero tokens, reserving LLMs strictly for edge cases.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 17, 2026
ai-agentspythonexpress

Security analysis

A100/100

Scanned October 17, 2026

npx -y skills add airshell/ai-optimizer --skill regex-vs-llm --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Regex Vs Llm?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Regex Vs Llm
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/airshell-regex-vs-llm/badge)](https://www.skillsdirectory.com/skills/airshell-regex-vs-llm)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: regex-vs-llm
description: >-
  Decision framework and hybrid pattern for choosing between deterministic
  regex and LLM extraction. Handles 95%+ of structured text tasks with zero
  tokens, reserving LLMs strictly for edge cases.
metadata:
  origin: AI Optimizer
  license: MIT
---

# Zero-Token Text Extraction (Regex vs LLM)

A practical architectural pattern for parsing structured and semi-structured text (logs, invoices, tables, markdown, forms). Deterministic regular expressions handle 95%–98% of structured cases at **zero LLM tokens and sub-millisecond speed**. Reserve expensive LLM calls strictly for low-confidence edge cases.

## Decision Framework

```
Is the text format mostly structured or patterned?
├── Yes (>90% follows recurring patterns) → Start with Regex
│   ├── Regex parses cleanly (≥95% confidence) → Done (0 tokens consumed)
│   └── Low-confidence edge cases (<95%) → Forward edge cases to LLM validator
└── No (free-form natural narrative) → Use LLM directly
```

## Hybrid Architecture Pattern

```
Source Text
    │
    ▼
[Regex Parser] ────────── Extracts structured records (95-98% accuracy, 0 tokens)
    │
    ▼
[Confidence Scorer] ───── Validates fields, lengths, and expected formats
    │
    ├── High Confidence (≥0.95) ──→ Instant Output (0 tokens, <1ms)
    │
    └── Low Confidence (<0.95) ───→ [Lightweight LLM Validator] ──→ Final Output
```

## Implementation Example (Python)

```python
import re
from dataclasses import dataclass

@dataclass(frozen=True)
class ExtractedRecord:
    id: str
    title: str
    status: str
    confidence: float = 1.0

def parse_records(text: str) -> list[ExtractedRecord]:
    pattern = re.compile(r"#(?P<id>\d+)\s+-\s+(?P<title>.+?)\s+\[(?P<status>\w+)\]")
    records = []
    for match in pattern.finditer(text):
        records.append(ExtractedRecord(
            id=match.group("id"),
            title=match.group("title").strip(),
            status=match.group("status").upper(),
            confidence=1.0
        ))
    return records
```

## Production Benchmark Metrics

From production document and log parsing workloads:
- **Deterministic regex coverage**: ~98.0% of records
- **Edge cases requiring LLM**: ~2.0%
- **Net token cost savings**: **95% to 98% reduction vs all-LLM parsing**
- **Latency**: Sub-millisecond execution vs seconds of LLM network latency

## Best Practices

- Always write tests for common regex patterns before deploying.
- Use programmatic confidence checks (required keys, min length, expected enums) to flag items needing LLM review.
- Never burn LLM tokens extracting text that a simple regular expression solves deterministically.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.