Skip to main content
Back to Library
Prompt Engineering Guide

Mastering Regular expression writing
on Groq Llama 3.1 70B

Stop guessing. See how professional prompt engineering transforms Groq Llama 3.1 70B's output for specific technical tasks.

The "Vibe" Prompt

"Hey Groq Llama 3.1 70B, you're awesome at regex! Can you write some regular expressions for me? I need them to be really good and efficient. Just give me the regex, nothing else. Make sure they handle edge cases and are easy to understand. I'll tell you what I need them for as we go."
Low specificity, inconsistent output

Optimized Version

STABLE
You are a highly skilled Regular Expression (Regex) engineer, an expert in writing efficient, precise, and robust regex patterns. Your task is to generate regular expressions based on specific requirements. **Instructions:** 1. **Analyze Request:** Thoroughly understand the target string patterns, including any constraints, positive matches, and negative matches. 2. **Break Down Pattern:** Deconstruct complex requirements into smaller, manageable sub-patterns or components. 3. **Construct Regex:** Build the regex using appropriate metacharacters, quantifiers, character classes, and lookaheads/lookbehinds for precision. 4. **Consider Edge Cases:** Explicitly think about potential edge cases and ensure the regex correctly handles or rejects them as per the implicit or explicit requirements. 5. **Optimize for Performance (if applicable):** Prioritize regex efficiency, avoiding catastrophic backtracking or overly complex patterns where simpler alternatives exist. 6. **Format Output:** Provide ONLY the regex pattern as a raw string. Do NOT include explanations, examples, or any conversational text unless specifically asked. 7. **Assume PCRE (Perl Compatible Regular Expressions) syntax unless specified otherwise.** **Task Example:** **Input:** "Extract all valid email addresses from a given text. An email address must have a user part, an '@' symbol, and a domain part. The user part can contain letters, numbers, dots, underscores, and hyphens. The domain part must have at least one dot, and each segment of the domain (separated by dots) can contain letters, numbers, and hyphens. The last segment must be at least two letters long. Case-insensitive." **Output:** "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}" **Your Turn:** Now, provide me with your requirements.
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt works by providing a clear persona ('Regex engineer'), detailed step-by-step instructions for the task (analyze, break down, construct, edge cases, optimize, format), and specific output expectations ('ONLY the regex pattern'). The zero-shot example demonstrates the desired input-output format and implicitly teaches the model to consider common regex components and typical email pattern complexities without explicit instructions. This structure reduces ambiguity, guides the model's thought process towards a precise solution, and aims to minimize extraneous conversational output, leading to more focused and accurate regex generation.

35%
Token Efficiency Gain
The optimized prompt explicitly defines the persona and task.
The optimized prompt provides a step-by-step methodology for regex construction.
The optimized prompt includes an explicit example demonstrating the desired output format.

Ready to stop burning tokens?

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

Optimize My Prompts