🔍 Regular Expressions Are Hard. AI Makes Them Easy.
Need to extract emails? Phone numbers? Dates? AI generates regex from examples. No more regex debugging hell.
📝 The Prompt
Generate a regular expression that matches: [Provide examples of what you want to match] Example inputs that SHOULD match: - [example 1] - [example 2] - [example 3] Example inputs that should NOT match: - [bad example 1] - [bad example 2] Language: [JavaScript/Python/PCRE/ECMAScript] Requirements: - Explain each part of the regex - Provide test cases - Show how to use in code Example: "Extract all email addresses from text"
✅ Example Output
User: "Extract phone numbers in formats: (123) 456-7890, 123-456-7890, 123.456.7890"
AI:
Regex: \(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})
Breakdown:
- \(? - Optional opening parenthesis
- (\d{3}) - Area code (3 digits)
- \)? - Optional closing parenthesis
- [-.\s]? - Optional separator (dash, dot, space)
- (\d{3}) - Next 3 digits
- [-.\s]? - Optional separator
- (\d{4}) - Last 4 digits
Example usage (Python):
import re
pattern = r'\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})'
matches = re.findall(pattern, text)
formatted = [f'({a}) {b}-{c}' for a,b,c in matches]
💡 Use Cases
- Extract emails, URLs, phone numbers
- Validate passwords, usernames, credit cards
- Parse log files (IP addresses, timestamps)
- Extract specific patterns from text
- Data cleaning and transformation
“Regex always breaks my brain. Described what I needed to AI. Got perfect regex in 10 seconds. Tested, worked. Never writing regex manually again.”
