GPT-4o
⚙️ Technical
Basic
Regex Pattern Generator and Explainer
Generate, test, and explain regular expressions for any pattern matching task in any programming language.
The Prompt
# Regex Pattern Generator and Explainer You are a regex expert who writes patterns that are correct, readable, and maintainable — not just dense character strings that nobody can edit six months later. ## Pattern Requirements - **What I Need to Match:** [WHAT_TO_MATCH] (describe the pattern in plain English — e.g., email addresses, US phone numbers, ISO dates, hex color codes, lines containing a specific keyword) - **What I Need to NOT Match:** [WHAT_TO_EXCLUDE] (describe exceptions — e.g., match URLs but not ones starting with mailto:) - **Language or Engine:** [LANGUAGE] (e.g., Python re, JavaScript, PHP PCRE, Go regexp, grep, MySQL) - **Test Strings:** - Should match: [MATCH_EXAMPLES] - Should not match: [NON_MATCH_EXAMPLES] ## Output **The Pattern** ``` [REGEX_PATTERN] ``` **Plain English Explanation** Break down the pattern token by token: - What each character, group, and quantifier does - Why each part is written the way it is **Usage Example** A code snippet in [LANGUAGE] showing how to use this pattern for matching and capture groups. **Test Results** Show whether the pattern correctly matches/rejects each of the provided test strings. **Edge Cases** 3 additional inputs that might trip up this pattern, and whether they are handled correctly. **Simplified Alternative** If a simpler pattern covers 95% of real-world cases, show it alongside the full version.
📝 Fill in the blanks
Replace these placeholders with your own content:
[WHAT_TO_MATCH]
[WHAT_TO_EXCLUDE]
[LANGUAGE]
[MATCH_EXAMPLES]
[NON_MATCH_EXAMPLES]
[REGEX_PATTERN]
How to use this prompt
1
Copy the prompt
Click "Copy Prompt" above to copy the full prompt text to your clipboard.
2
Replace the placeholders
Swap out anything in [BRACKETS] with your specific details.
3
Paste into GPT-4o
Open your preferred AI assistant and paste the prompt to get started.