Skip to main content
Back to Library
Prompt Engineering Guide

Mastering Regular expression writing
on Mixtral 8x22B

Stop guessing. See how professional prompt engineering transforms Mixtral 8x22B's output for specific technical tasks.

The "Vibe" Prompt

"Hey Mixtral, write me a regex to match email addresses. Make sure it's good."
Low specificity, inconsistent output

Optimized Version

STABLE
You are a highly skilled regular expression engineer tasked with creating a robust regex for email address validation. Follow these steps: 1. **Understand Requirements**: The regex should validate standard email formats, including common TLDs, subdomains, and special characters in the local part, but avoid overly permissive patterns that might match invalid addresses. 2. **Break Down the Problem**: * Local Part (before '@'): Allow alphanumeric, dots, underscores, percentage signs, plus signs, and hyphens. Dots and hyphens should not appear consecutively or at the beginning/end. Length should be reasonable. * 'at' symbol: A single '@' character. * Domain Part (after '@'): * Subdomain(s): Allow alphanumeric and hyphens. Hyphens should not be at the beginning/end. Multiple dot-separated subdomains allowed. * Top-Level Domain (TLD): At least two alphanumeric characters. Common TLDs like '.com', '.org', '.net', '.co.uk' etc. should be covered implicitly by the alphanumeric rule, but avoid single-character TLDs. 3. **Construct Regex Components**: Build a regex for each part identified in step 2. 4. **Combine Components**: Integrate the individual regex components into a complete expression. 5. **Refine and Test (Mental Walkthrough)**: Consider edge cases. For instance, what about `test@localhost`? What about `john.doe@email-service.co.uk`? What about `user+tag@domain.com`? Ensure the regex handles these correctly while rejecting `user@-domain.com` or `user@domain..com`. Generate the optimized regular expression. Provide only the regex string itself, without explanation or surrounding text.
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt leverages chain-of-thought by breaking down the complex task of email regex generation into smaller, manageable steps. It provides explicit constraints and expectations for each part of the email address (local part, '@', domain part, TLD), guiding the model towards a more accurate and robust solution. The 'Refine and Test' step encourages the model to internally validate its output against common and edge cases, mimicking a human problem-solving approach. This structured approach significantly reduces ambiguity and improves the likelihood of a high-quality output compared to the vague 'vibe_prompt'.

0%
Token Efficiency Gain
The 'optimized_prompt' will produce a more robust and widely accepted email regex than the 'vibe_prompt'.
The 'vibe_prompt' is likely to generate a simpler, less comprehensive, or potentially overly permissive regex.
The 'optimized_prompt' guides the model to consider specific character sets, length constraints, and structural rules for different parts of an email, which a human would do.

Ready to stop burning tokens?

Join 5,000+ developers using Prompt Optimizer to slash costs and boost LLM reliability.

Optimize My Prompts