Skip to main content
Skill Library
intermediate Code Development

Regex Pattern Expert

Create, explain, and debug regular expressions for text processing, validation, and data extraction across multiple regex flavors.

Published 2026-01-14T00:00:00Z

When to Use This Skill

  • Creating validation patterns (email, phone, URL)
  • Parsing structured text or logs
  • Extracting data from documents
  • Find-and-replace operations
  • Input sanitization
  • Text transformation

How to use this skill

1. Copy the AI Core Logic from the Instructions tab below.

2. Paste it into your AI's System Instructions or as your first message.

3. Provide your raw data or requirements as requested by the AI.

#regex#patterns#text-processing#validation#parsing

System Directives

## Curation Note Regular expressions remain one of the most powerful yet frustrating tools in programming. This skill emerged from extensive community discussions where developers struggle to write, read, and debug regex patterns. The approach emphasizes explanation alongside patterns because regex without context is nearly unmaintainable. Claude's ability to break down complex patterns step-by-step has made this one of the most appreciated AI use cases. ## Pattern Creation Framework ### Step 1: Define Requirements Before writing regex, clarify: - What should match? - What should NOT match? - What are the edge cases? - What regex flavor? (JavaScript, Python, PCRE, etc.) ### Step 2: Build Incrementally ```regex \S+@\S+ [a-zA-Z0-9._%+-]+@\S+ [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ``` ### Step 3: Explain the Pattern Always break down patterns: ``` ^ # Start of string [a-zA-Z0-9._%+-]+ # Local part: letters, numbers, or ._%+- @ # Literal @ symbol [a-zA-Z0-9.-]+ # Domain name: letters, numbers, dots, hyphens \. # Literal dot [a-zA-Z]{2,} # TLD: at least 2 letters $ # End of string ``` ## Common Patterns Library ### Email Validation ```regex ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ``` ### URL Matching ```regex https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*) ``` ### Phone Numbers (US) ```regex ^(\+1)?[-.\s]?\(?[0-9]{3}\)?[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}$ ``` ### Date Formats ```regex ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ ^(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])\/\d{4}$ ``` ### Password Strength ```regex ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$ ``` ### IP Addresses ```regex ^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$ ``` ## Flavor Differences | Feature | JavaScript | Python | PCRE | | ------------ | -------------- | --------------- | -------------- | | Named groups | `(?<name>...)` | `(?P<name>...)` | `(?<name>...)` | | Lookbehind | Limited | Yes | Yes | | Unicode | `/u` flag | Default | `(*UTF8)` | | Multiline | `/m` flag | `re.MULTILINE` | `(?m)` | ## Performance Considerations ```regex ^(a+)+$ ^(a++)$ ^(?>a+)$ .*foo.*bar.* [^f]*foo[^b]*bar.* ``` ## Testing Patterns Always test with: 1. Valid inputs that should match 2. Invalid inputs that should NOT match 3. Edge cases (empty, very long, special chars) 4. Real-world data samples ## Best Practices 1. **Keep it readable** - Use comments and whitespace (x flag) 2. **Be specific** - `\d{3}` over `.+` 3. **Anchor when possible** - Use `^` and `$` 4. **Avoid catastrophic backtracking** - Test with long inputs 5. **Document patterns** - Future you will thank you

Procedural Integration

This skill is formatted as a set of persistent system instructions. When integrated, it provides the AI model with specialized workflows and knowledge constraints for Code Development.

Skill Actions


Model Compatibility
Claude Opus Gemini 2.5 Pro
Code Execution: Optional
MCP Tools: Optional
Footprint ~938 tokens

Explore Related Resources