$ recombobulate _
home / tips / generate-regex-patterns-by-describing-them-in-plain-english
0

Generate Regex Patterns by Describing Them in Plain English

bagwaa @bagwaa · Mar 25, 2026 · Prompting
generate-regex-patterns-by-describing-them-in-plain-english

Regex is powerful but notoriously hard to read and write correctly under pressure. Claude can handle the syntax while you focus on what you actually need to match.

Just describe the pattern in plain English:

Write a regex that matches UK postcodes in these formats:
SW1A 1AA, W1A 0AX, EC1A 1BB — with an optional space in the middle.
It should match the full string, not just find it inside a longer string.
Give me the pattern for JavaScript and also for PHP.

Claude will produce the pattern, explain each component, and often include a few test cases showing what it matches and what it doesn't:

// JavaScript
const uk_postcode = /^[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}$/i;

You can also go the other way — paste a gnarly regex you've inherited and ask Claude to explain what it does:

What does this regex match? Explain each part:
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/

This is also great for refining patterns — ask Claude to modify an existing regex to handle a new edge case without breaking what already works.

If you can describe what it should match, Claude can write the regex — and explain it so you actually understand it too.

~/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