Prompt Engineering Guide
Mastering Regular expression writing
on Qwen 2.5 72B
Stop guessing. See how professional prompt engineering transforms Qwen 2.5 72B's output for specific technical tasks.
The "Vibe" Prompt
"Write a regex to extract all email addresses from a given text. Assume standard email format."
Low specificity, inconsistent output
Optimized Version
You are an expert in regular expressions. Your task is to extract all valid email addresses from a given text. An email address is considered valid if it follows the standard format: `username@domain.tld`. The username can contain alphanumeric characters, periods (.), hyphens (-), and underscores (_). The domain part can contain alphanumeric characters and hyphens (-), and the top-level domain (TLD) consists of 2 to 4 alphabetic characters. Multiple subdomains are allowed (e.g., `user@sub.domain.tld`).
Think step-by-step:
1. Define the character set for the username.
2. Define the character set for the domain name (excluding TLD).
3. Define the character set and length for the TLD.
4. Combine these parts with '@' and '.' separators.
5. Ensure non-greedy matching or global matching if multiple emails are expected.
Input Text: "Please contact us at support@example.com or sales-dept@my-company.co.uk for inquiries. Also, john.doe_123@mail.sub.net is available."
Output only the regular expression pattern. Do not include any explanation or example usage.
Structured, task-focused, reduced hallucinations
Engineering Rationale
The optimized prompt provides significantly more detail and constraints, guiding the model to a more precise and robust regex. The chain-of-thought section breaks down the problem, which helps the model to structure its thinking, leading to a more accurate solution. It specifies valid characters, domain structure, and TLD length, moving beyond a 'standard email format' which can be ambiguous. It also explicitly asks for only the regex pattern, reducing extraneous output.
0%
Token Efficiency Gain
The `optimized_prompt` should produce a regex that correctly identifies 'support@example.com', 'sales-dept@my-company.co.uk', and 'john.doe_123@mail.sub.net'.
The `optimized_prompt`'s regex should NOT match invalid email-like strings such as 'bad@domain.' or 'user@.com'.
The `optimized_prompt` should strictly output only the regex pattern, without surrounding text or examples.
Ready to stop burning tokens?
Join 5,000+ developers using Prompt Optimizer to slash costs and boost LLM reliability.
Optimize My Prompts