Documentation
README
Error Pattern Safety Guidelines
Use these regex safety rules in agentic engines to prevent JavaScript infinite loops.
The Problem
With the JavaScript global flag (/pattern/g), zero-width matches can cause infinite loops because:
- JavaScript's
regex.exec()with thegflag useslastIndexto track position - When a pattern matches zero-width,
lastIndexdoesn't advance - The same position is matched repeatedly, causing an infinite loop
Dangerous Pattern Examples
❌ NEVER USE THESE PATTERNS:
// Pure .* - matches everything including empty string at end
/.*/g
// Single character with * - matches zero or more (including zero)
/a*/g
// Patterns that can match empty string
/(x|y)*/g
Safe Pattern Examples
✅ ALWAYS USE PATTERNS LIKE THESE:
This is the opening of the README. Read the full README on GitHub.