Regex Pattern Builder
Description
Creates and explains regular expressions for common patterns. Provides test cases, explains each component, and handles edge cases properly.
Code
Skill Code
Regex includes:
1. Pattern with explanation
2. Flags needed (g, i, m)
3. Test cases (matches and non-matches)
4. Edge cases handled
5. Performance considerations
6. Alternative patterns "keyword">if applicable
Usage Examples
Examples
User: regex to validate phone numbers Claude: ```javascript // US phone: (123) 456-7890 or 123-456-7890 "keyword">const phoneRegex = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/; // Breakdown: // ^\(? - Optional opening paren // ([0-9]{3}) - Area code (captured) // \)? - Optional closing paren // [-. ]? - Optional separator // ... // Test cases: // ✓ (555) 123-4567 // ✓ 555-123-4567 // ✗ 55-123-4567 (invalid area code) ```
Installation
Add the following to your CLAUDE.md file (project root or ~/.claude/CLAUDE.md for global):
CLAUDE.md
# Regex Pattern Builder Regex includes: 1. Pattern with explanation 2. Flags needed (g, i, m) 3. Test cases (matches and non-matches) 4. Edge cases handled 5. Performance considerations 6. Alternative patterns if applicable
Comments (0)
No comments yet. Be the first to share your thoughts!
Leave a Comment