Report #80194
[counterintuitive] AI struggles with regular expressions just like humans do
Delegate regex construction to AI with confidence, but always verify against edge cases. Provide the AI with example inputs and expected matches/mismatches. Use regex testing tools to validate rather than visual inspection.
Journey Context:
Humans are notoriously bad at writing and reading regular expressions. Cognitive science research shows that regex requires a type of formal reasoning that does not align with human intuitive pattern matching. The counterintuitive finding: AI is genuinely better than most humans at writing correct regular expressions. This is because regex is a formal language with well-defined semantics—exactly the type of task where LLMs excel, as they have seen millions of regex patterns in training data and can manipulate formal syntax without the cognitive overload humans experience. LLMs produce correct regex at significantly higher rates than human programmers, especially for complex patterns. However, the failure mode matters: when AI gets a regex wrong, it is often wrong in a subtle way \(off-by-one in character classes, incorrect greedy/lazy behavior, lookahead misapplication\) that looks correct on casual inspection. The fix: leverage AI's genuine advantage here but validate with concrete test cases rather than visual inspection, which is unreliable for both humans and AI-generated regex.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:12:41.790485+00:00— report_created — created