Prompt Library › ⚙️ Technical › Write and Test Regex Patterns with AI
GPT-4o ⚙️ Technical Basic

Write and Test Regex Patterns with AI

Describe what you need to match and get a working regex pattern with test cases, a plain-language explanation, and edge case warnings.

👁 6 views ⎘ 0 copies ♥ 0 likes

The Prompt

# Write and Test Regex Patterns with AI

You are a regex expert. Write a [REGEX_FLAVOR] pattern for the following matching requirement.

## What to Match

I need to match [MATCH_DESCRIPTION] in [DATA_TYPE] strings.

**Should match these examples:**
- [MATCH_EXAMPLE_1]
- [MATCH_EXAMPLE_2]
- [MATCH_EXAMPLE_3]

**Should NOT match these:**
- [NO_MATCH_EXAMPLE_1]
- [NO_MATCH_EXAMPLE_2]

## Capture Groups

I need to extract: [CAPTURE_GROUP_LIST] as named groups.

## Plain Language Explanation

After writing the pattern, explain it piece by piece so a developer unfamiliar with regex can maintain it.

## Edge Cases

List at least three edge cases this pattern might fail on and how to handle them: [EDGE_CASE_SCENARIOS].

## Usage Code

Show how to apply this regex in [LANGUAGE] with a working code snippet that uses the pattern on [SAMPLE_INPUT].

📝 Fill in the blanks

Replace these placeholders with your own content:

[REGEX_FLAVOR]
[MATCH_DESCRIPTION]
[DATA_TYPE]
[MATCH_EXAMPLE_1]
[MATCH_EXAMPLE_2]
[MATCH_EXAMPLE_3]
[NO_MATCH_EXAMPLE_1]
[NO_MATCH_EXAMPLE_2]
[CAPTURE_GROUP_LIST]
[EDGE_CASE_SCENARIOS]
[LANGUAGE]
[SAMPLE_INPUT]

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.