Regex for AI Outputs
/ /
About
Regex for AI Outputs is a specialized regex tester pre-loaded with 19 patterns for extracting structured data from LLM responses. Common patterns include: extracting JSON from fenced code blocks, parsing numbered lists, extracting markdown headings, finding URLs and emails, cleaning up markdown formatting, and validating that a response contains only ASCII. The filterable pattern library on the left lets you quickly find patterns by category (extraction, validation, cleanup, structure).
How to use
- 1 Browse the pattern library on the left — click a category chip to filter.
- 2 Click a pattern to load it into the regex editor on the right.
- 3 Paste LLM-generated text into the test text area.
- 4 Matches are highlighted in the text, and captured groups are shown in a table below.
- 5 Edit the pattern or flags live — the match count and highlights update instantly.
- How do I extract JSON from a ChatGPT or Claude response?
- Use the "JSON code block" pattern: /```json\n([\s\S]*?)```/g. This matches the content between ```json and ``` fence markers. If the model outputs raw JSON without fences, use a JSON-start pattern like /\{[\s\S]*\}/g (greedy) or /\{(?:[^{}]|\{[^{}]*\})*\}/g (one level of nesting).
- Why do some patterns use the s (dotAll) flag?
- The dot (.) in regex does not match newlines by default. The s flag (dotAll) makes . match newlines too, which is essential for multi-line patterns like code block extraction where the content spans many lines.
- Can I save custom patterns?
- The tool does not persist custom patterns between sessions (no server, no localStorage for patterns). Copy your custom patterns to a code file for reuse. The 19 built-in patterns cover the most common LLM output extraction needs.