Prompt Library ⚙️ Technical Generate Regex Patterns for Any Use Case
GPT-4o ⚙️ Technical Basic

Generate Regex Patterns for Any Use Case

Get the exact regex pattern you need — with explanation, edge case handling, and language-specific syntax for your environment.

👁 4 views ⎘ 0 copies ♥ 0 likes

The Prompt

# Generate Regex Patterns for Any Use Case

You are a regex expert who writes patterns that work in production and are understandable six months later.

## What I Need to Match

Pattern purpose: [PATTERN_PURPOSE]
Language/tool where this will run: [LANGUAGE_OR_TOOL]
Input examples to match:
- [VALID_EXAMPLE_1]
- [VALID_EXAMPLE_2]
- [VALID_EXAMPLE_3]

Input examples that must NOT match:
- [INVALID_EXAMPLE_1]
- [INVALID_EXAMPLE_2]

Edge cases I'm worried about: [EDGE_CASES]

## Pattern Design

**Simple version:**
Write the most readable regex that handles the core cases.

**Robust version:**
Write the production version that handles edge cases: [EDGE_CASES]

**Explanation:**
Break down each component of the robust pattern using inline comments or a table:

| Component | What it matches | Why it's there |

## Language-Specific Implementation

Show the exact code to use this pattern in [LANGUAGE_OR_TOOL], including:
- Import or library to use
- How to compile the pattern (for performance if used in a loop)
- How to extract matched groups vs. test for a match

## Test Cases

Write a test suite with:
- 5 inputs that should match and why
- 5 inputs that should not match and why
- The 2 edge cases most likely to cause false positives or negatives

📝 Fill in the blanks

Replace these placeholders with your own content:

[PATTERN_PURPOSE]
[LANGUAGE_OR_TOOL]
[VALID_EXAMPLE_1]
[VALID_EXAMPLE_2]
[VALID_EXAMPLE_3]
[INVALID_EXAMPLE_1]
[INVALID_EXAMPLE_2]
[EDGE_CASES]

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.