Skip to main content
Back to Library
Prompt Engineering Guide

Mastering Regular expression writing
on Claude 3.5 Haiku

Stop guessing. See how professional prompt engineering transforms Claude 3.5 Haiku's output for specific technical tasks.

The "Vibe" Prompt

"Hey Claude, can you help me write a regular expression? I need one to match email addresses."
Low specificity, inconsistent output

Optimized Version

STABLE
{ "task": "Regular Expression Generation", "constraints": ["Must match standard email address format (e.g., user@domain.com, user.name@sub.domain.co)", "Should not match invalid formats (e.g., user@.com, @domain.com)", "Be as concise as possible while maintaining accuracy"], "examples": ["valid@example.com", "test.user123@sub.domain.ai", "another-one@mail-service.co.uk"], "negative_examples": ["invalid-email", "@domain.com", "user@domain.", "user@domain.c", "user@domain..com"], "output_format": "Return only the regular expression string.", "reasoning_steps_required": true }
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt provides clear, structured instructions using a JSON format which is easier for the model to parse. It explicitly defines the task, constraints, positive and negative examples, and the desired output format. Requiring 'reasoning_steps_required' helps the model articulate its thought process if needed, leading to more accurate results. This structure reduces ambiguity and provides concrete boundaries for the task, making it more likely Claude 3.5 Haiku will produce the desired output efficiently.

15%
Token Efficiency Gain
The optimized prompt explicitly defines valid and invalid examples.
The optimized prompt requests only the regex string, reducing unnecessary conversational filler.
The optimized prompt uses structured fields to convey information, improving machine readability.

Ready to stop burning tokens?

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

Optimize My Prompts