Skip to main content
Back to Library
Prompt Engineering Guide

Mastering Regular expression writing
on Phi-3.5 MoE

Stop guessing. See how professional prompt engineering transforms Phi-3.5 MoE's output for specific technical tasks.

The "Vibe" Prompt

"regex for email addresses."
Low specificity, inconsistent output

Optimized Version

STABLE
You are an expert in regular expressions. Your goal is to provide a highly accurate and robust regular expression for common email address formats. Think step-by-step to include consideration for: 1. **Local part:** Alphanumeric, dots, hyphens, underscores are allowed. It should not start or end with a dot or hyphen. Multiple consecutive dots or hyphens are not allowed. Minimum 1 character. 2. **Separator:** A single '@' symbol. 3. **Domain part:** a. **Hostname:** Alphanumeric, dots, hyphens. It should not start or end with a hyphen. Multiple consecutive dots are not allowed. Minimum 1 character. b. **Top-Level Domain (TLD):** At least two alphabetic characters. It should be separated from the hostname by a dot. Maximum 6 characters. Formulate the regex to be as widely compatible as possible (e.g., PCRE, Python re module). Explain your thought process in arriving at the final regex. Provide only the regex string wrapped in triple backticks, followed by your explanation.
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt uses Chain-of-Thought (CoT) by breaking down the complex task of writing a robust email regex into smaller, manageable sub-problems (local part, separator, domain part, TLD) with specific constraints. It sets a clear persona ('expert in regular expressions') and explicitly asks for a step-by-step thinking process. This structured approach guides the model to comprehensive considerations, reducing the likelihood of common regex pitfalls and improving accuracy. It also specifies output format, which aids parsing subsequent steps.

0%
Token Efficiency Gain
The provided regex should correctly match 'test@example.com'.
The provided regex should correctly match 'firstname.lastname@sub.domain.co.uk'.
The provided regex should correctly match 'user-name_123@mailbox.org'.

Ready to stop burning tokens?

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

Optimize My Prompts