Regex from Plain English
Describe what you want to match and get a working pattern back, with each component explained.
Describing what you want precisely
- Say whether it must match the whole string —"A valid postcode" and "postcodes appearing in this text" produce different patterns — one anchored, one not.
- Give exact quantities —"Three to five digits" beats "some digits". An unbounded quantifier where a bounded one was meant is the commonest over-match.
- Include a near-miss —Naming something that should not match is usually more informative than another positive example.
- Say which parts you need to extract —That determines where capture groups go and whether they get names.
- Name the target language —JavaScript, Python and PCRE differ on lookbehind, atomic groups and named-group syntax. Say which engine the pattern is for.
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.
More in AI Tools
See all ai tools.