Regex Generator for AI
A library of common Regular Expression patterns for parsing JSON, code blocks, and other structures from LLM outputs.
Extract JSON Object
Finds and extracts a JSON object (curly braces) from a string.
\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}Here is the result: {"name": "John", "age": 30}.Extract JSON Array
Finds and extracts a JSON array (brackets) from a string.
\[[^\[\]]*(?:\[[^\[\]]*\][^\[\]]*)*\]The output is: ["apple", "banana"].Extract Code Block
Extracts content from Markdown fenced code blocks (```...```).
```(?:[a-zA-Z0-9]*)?\n([\s\S]*?)\n``````javascript\nconsole.log("Hello");\n```Extract Email Address
Finds a standard email address pattern.
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}Contact us at support@example.com for help.Extract URL
Finds HTTP/HTTPS URLs.
https?:\/\/[^\s]+Visit https://example.com/page for more info.Extract Text Inside Quotes
Extracts content between double quotes.
"([^"]*)"The answer is "42".Frequently Asked Questions
Why use Regex on AI output?
LLMs do not always return cleanly parseable data. Sometimes they add conversational preambles ("Here is the JSON:") or extra text after the structured output. Regex helps you extract just the part you need.
Is Regex reliable for JSON?
For simple flat JSON, yes. For deeply nested or complex JSON, Regex can be fragile. A safer approach is to use Regex to isolate the block, then use JSON.parse() for actual parsing in a try/catch.
How do I use these in JavaScript?
const match = text.match(/YOUR_REGEX/g);. The /g flag returns all matches.