AI generated prompt for Regex Pattern Generator and Tester
**Context**:
Regular expressions (regex) are a powerful tool used for matching patterns in strings, but creating and testing them can be challenging, especially for complex patterns. A regex pattern generator and tester is a tool that can help users create, test, and refine their regex patterns.
**Detailed Instructions**:
Design a comprehensive regex pattern generator and tester that can perform the following functions:
1. **Pattern Generation**: Given a set of example strings (both matching and non-matching), generate a regex pattern that matches the positive examples and rejects the negative ones.
2. **Pattern Testing**: Allow users to input their own regex patterns and test them against a set of strings to see which ones match and which ones do not.
3. **Pattern Refinement**: Provide suggestions for refining the generated or user-inputted regex patterns to improve their accuracy or efficiency.
4. **Error Handling**: Identify and report any errors in the regex patterns, such as syntax errors or catastrophic backtracking.
5. **Explanation**: Offer a breakdown of how the regex pattern works, including explanations of each part of the pattern and how it contributes to the overall match.
**Output Format**:
The output should be in a JSON format with the following keys:
- `pattern`: The generated or tested regex pattern.
- `matches`: A list of strings that match the pattern.
- `non_matches`: A list of strings that do not match the pattern.
- `errors`: A list of error messages, if any.
- `explanation`: A detailed explanation of the regex pattern.
**Examples**:
- Input: A set of example strings, such as ["hello", "world", "hello world"] as positive examples and ["goodbye", "foo"] as negative examples.
- Output: A regex pattern that matches the positive examples, such as `hello|world|hello world`, along with explanations and test results.
- Input: A user-inputted regex pattern, such as `\d{4}-\d{2}-\d{2}`, and a set of test strings, such as ["2022-01-01", "20220101", "2022/01/01"].
- Output: The input pattern, a list of matching strings (e.g., ["2022-01-01"]), a list of non-matching strings (e.g., ["20220101", "2022/01/01"]), and an explanation of the pattern.This coding prompt is designed to help you get better results from AI assistants like ChatGPT, Claude, and Gemini. Here's how to make the most of it:
💡 Pro tip: Save this prompt to your collection to use it again later. Well-crafted prompts can save hours of back-and-forth with AI.
Adjust the prompt to match your specific industry, audience, or use case. Adding relevant context improves output quality.
Specify your desired output length (e.g., "in 200 words" or "in 3 bullet points") to get more targeted responses.
Add tone instructions like "professional," "casual," or "technical" to match your brand voice.
Include an example of the output format you want to help the AI understand your expectations.
This prompt has been tested and optimized for all major AI models. For best results with coding-related prompts, consider using an AI-powered IDE like Cursor or Windsurf.
Learn more about using prompts effectively with our comprehensive guides:
0 people found this prompt helpful
Based on 0 reviews
Be the first to share your experience with this prompt!
This prompt was reviewed and verified to work with current AI models.
Tested with ChatGPT, Claude & Gemini. Reviewed by community users.
AI prompts work best when you customize them for your specific situation. Follow these steps to get the most out of Regex Pattern Generator And Tester.