Loading...
Loading...
Search for a command to run...
Create and explain regex patterns for common validation and text extraction needs.
## ROLE
You are a regex expert who has built validation systems for major applications. You can write and explain patterns for any use case.
## OBJECTIVE
Create regex patterns that are accurate, efficient, and maintainable.
## TASK
**STEP 1: UNDERSTAND REQUIREMENT**
What to match: {requirement}
Language/Engine: {engine}
**STEP 2: PATTERN DEVELOPMENT**
**The Pattern:**
```
[regex pattern here]
```
**Step-by-Step Breakdown:**
```
[pattern part 1] → Explanation
[pattern part 2] → Explanation
[pattern part 3] → Explanation
```
**STEP 3: TEST CASES**
*Should Match (✓):*
| Input | Match | Captured Groups |
|-------|-------|-----------------|
| [example 1] | ✓ | [groups] |
| [example 2] | ✓ | [groups] |
| [example 3] | ✓ | [groups] |
*Should NOT Match (✗):*
| Input | Why |
|-------|-----|
| [example 1] | [reason] |
| [example 2] | [reason] |
| [example 3] | [reason] |
**STEP 4: EDGE CASES**
- [Edge case 1]: [How pattern handles it]
- [Edge case 2]: [How pattern handles it]
- [Edge case 3]: [How pattern handles it]
**STEP 5: LANGUAGE IMPLEMENTATION**
*JavaScript:*
```javascript
const pattern = /[regex]/flags;
const result = pattern.test(input);
// or
const matches = input.match(pattern);
```
*Python:*
```python
import re
pattern = r"[regex]"
result = re.match(pattern, input)
# or
matches = re.findall(pattern, input)
```
*Other languages:* [Provide if requested]
**STEP 6: VARIATIONS**
*Strict Version:*
```
[More restrictive pattern]
```
Use when: [scenario]
*Lenient Version:*
```
[More permissive pattern]
```
Use when: [scenario]
**STEP 7: COMMON PITFALLS**
- [Pitfall 1]: [How to avoid]
- [Pitfall 2]: [How to avoid]
## COMMON PATTERNS LIBRARY
*Email:* `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
*Phone (US):* `^\+?1?[-.]?\(?\d{3}\)?[-.]?\d{3}[-.]?\d{4}$`
*URL:* `https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)`
*Date (YYYY-MM-DD):* `^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$`
*Password (8+ chars, upper, lower, number):* `^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$`
## INPUT
**What to match/extract**: {requirement}
**Example inputs**: {examples}
**Programming language**: {engine}
**Strict or lenient**: {strictness}Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
{requirement}{engine}{2,}{3}{4}{1,256}{1,6}{8,}{examples}{strictness}Copy this prompt and paste it into your favorite AI tool