$ recombobulate _
home / tips / ask-claude-to-explain-and-document-cryptic-regex-patterns
0

Ask Claude to Explain and Document Cryptic Regex Patterns

bagwaa @bagwaa · Mar 25, 2026 · Prompting
ask-claude-to-explain-and-document-cryptic-regex-patterns

Regex is easy to write once and impossible to understand six months later. When you inherit a pattern you can't decipher, paste it to Claude and ask for a plain-English breakdown plus a commented version using the verbose flag — then you'll actually understand it when you need to change it.

Ask Claude:
"Explain this regex and rewrite it with inline comments using the verbose/x flag:
^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"...\")@..."

Claude produces a readable, commented version:

import re

email_pattern = re.compile(r"""
    ^                              # Start of string
    (?:
        [a-z0-9!#$%&'*+/=?^_`{|}~-]+      # Local part: allowed characters
        (?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)* # Dots allowed, not consecutively
    )
    @                              # Literal @ separator
    (?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+  # Domain labels with dots
    [a-z0-9](?:[a-z0-9-]*[a-z0-9])?$        # Top-level domain
""", re.VERBOSE | re.IGNORECASE)

Claude will also point out edge cases the regex doesn't handle — in this case, it doesn't match IP address literals or some valid RFC 5322 formats — and suggest whether a simpler pattern would cover your actual use case just as well.

This pairs well with the tip on generating new regex from descriptions: use Claude to generate, and use Claude to document.

If you can't explain a regex, Claude can — and it'll tell you how to make it better.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Ask Claude to Scaffold New Features Using Your Existing Code Conventions

Before asking Claude to scaffold a new feature, point it at your existing code first — it will match your naming, structure, error handling, and test patterns exactly rather than defaulting to framework boilerplate.

bagwaa @bagwaa · 2 hours ago
0
Describe the Entire Feature in Plain English Before Claude Starts Building

Give Claude the full picture upfront before it writes any code, so it builds the right thing the first time with fewer correction rounds.

bagwaa @bagwaa · 3 hours ago
0
Pass Multiline Prompts to Claude Code with Shell HEREDOCs

Complex prompts are unreadable as escaped single-liners. Use shell HEREDOCs to write clean, structured prompts directly in your scripts.

bagwaa @bagwaa · 6 hours ago