Skip to main content
Back to Library
Prompt Engineering Guide

Mastering Regular expression writing
on Perplexity Online 70B

Stop guessing. See how professional prompt engineering transforms Perplexity Online 70B's output for specific technical tasks.

The "Vibe" Prompt

"Write a regular expression to extract all email addresses from a given text."
Low specificity, inconsistent output

Optimized Version

STABLE
You are an expert in regular expressions, known for crafting highly robust and efficient patterns. Your task is to extract all valid email addresses from a provided text. Focus on a pattern that covers standard email formats (e.g., user@domain.com, user.name@sub.domain.co.uk) while minimizing false positives. Consider the following steps: 1. Start with defining valid characters for the local part (before the '@'). 2. Define the '@' symbol. 3. Define valid characters for the domain part (after the '@'). 4. Ensure a top-level domain (TLD) of at least two characters. 5. Think about edge cases or common variations to include/exclude consciously. 6. Prioritize readability and efficiency. Expected Output: A single regular expression string encapsulated in backticks. Do not include any explanations or examples, just the regex string itself. Example text for your internal thought process (do not output the result for this): 'Contact us at info@example.com or support@sub.domain.co.uk. Invalid: test@.com, @test.com, user@domain, user@domain.a.' Now, generate the regex.
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt leverages a chain-of-thought approach, guiding the model through the methodical construction of a regular expression. It establishes an 'expert persona' to encourage a high-quality output. By explicitly breaking down the problem into sub-steps (local part, @, domain part, TLD validation, edge cases), it primes the model to consider all critical components. The prompt also sets clear expectations for the output format (regex string only) and provides an internal example to help the model's 'thought process' without requiring it to generate output for it. This structured approach reduces ambiguity and directs the model towards a more accurate and comprehensive solution compared to the vague 'vibe prompt'.

0%
Token Efficiency Gain
The model should produce a single regex string.
The regex should correctly identify common email formats.
The regex should avoid common false positives (e.g., missing TLDs, invalid local parts).

Ready to stop burning tokens?

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

Optimize My Prompts