Skip to main content
Back to Library
Prompt Engineering Guide

Mastering Regular expression writing
on Mistral Large 2

Stop guessing. See how professional prompt engineering transforms Mistral Large 2's output for specific technical tasks.

The "Vibe" Prompt

"Can you write a regular expression to validate an email address? Make it robust."
Low specificity, inconsistent output

Optimized Version

STABLE
You are an expert in regular expressions and email validation standards (RFCs 5322, 6854). Your task is to generate a regular expression that robustly validates an email address according to these standards, aiming for high accuracy while minimizing false positives/negatives. **Output Format:** ```regex YOUR_REGEX_HERE ``` **Constraints:** - Must handle common edge cases (e.g., plus addressing like `user+tag@domain.com`, subdomains, TLDs). - Must not be overly permissive to invalid characters or structures. - Should not be overly restrictive, disallowing valid but less common formats. - The regex should be PCRE (Perl Compatible Regular Expressions) compliant if possible, or clearly specify the regex engine if not. - Provide a brief (1-2 sentence) explanation of key components if the regex is complex.
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt leverages several key principles: 1. **Role Assignment:** It explicitly assigns a 'expert' persona, which subtly encourages a higher quality, more detailed response. 2. **Clarity & Specificity:** Instead of 'robust,' it defines robustness by referencing RFC standards and specifying common edge cases to handle. 3. **Output Format:** It dictates a clear output format, making the response easily parsable or usable programmatically. 4. **Constraints/Guardrails:** It provides explicit constraints (e.g., PCRE, not overly permissive/restrictive) which guide the model towards a more accurate and useful solution, reducing ambiguity. 5. **Chain-of-Thought (Implicit):** By requiring an explanation for complex regexes, it encourages the model to 'think through' its solution and justify its components. 6. **Reduced Ambiguity:** The original prompt is vague, leading to potentially varied interpretations of 'robust.' The optimized prompt removes this ambiguity by defining 'robust' within the context of email validation standards.

0%
Token Efficiency Gain
The optimized prompt explicitly mentions RFC standards for email validation.
The optimized prompt requests PCRE compliance or engine specification.
The optimized prompt asks for an explanation of complex regex components.

Ready to stop burning tokens?

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

Optimize My Prompts