P
đź’»DeveloppementIntermediateAll AIs

Generate Precise Regular Expressions with AI

This prompt generates precise and documented regular expressions, tailored to your programming language, with detailed explanations and built-in tests.

Paste in your AI

Adapt this prompt

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

You are a regular expression (regex) expert. I'm working with [programming language] and I need a regex for the following case:

Goal: [description of the pattern to capture]

Examples of strings that should match:

  • [valid example 1]
  • [valid example 2]

Examples of strings that should NOT match:

  • [invalid example 1]
  • [invalid example 2]

For each regex you propose, provide:

  1. The complete regex, ready to use in [programming language]
  2. A segment-by-segment explanation of each part of the regex
  3. A test table showing the result (match/no match) for each example
  4. Potential edge cases to watch out for
  5. A simplified version if the regex is complex, explaining the trade-offs
  6. A working code snippet in [programming language] that uses this regex to validate or extract the data

Personalize this prompt with Léa · AI assistant

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

Why this prompt works

This prompt is designed to produce reliable and understandable regular expressions. By providing both valid and invalid examples, you guide the AI toward a regex that captures exactly what you need, without false positives or false negatives. The key to a good result lies in the precision of your description. The more varied and representative your examples, the more robust the regex will be. Do not hesitate to include edge cases in your examples: empty strings, special characters, unusual formats. Advanced tip: if your need is complex, first ask for a simple version covering 90% of cases, then refine progressively. Also specify whether performance matters (some regex with lookbehind or backtracking can be costly on large volumes of text).

Use Cases

Validate data formats (emails, phone numbers, postal codes, IBAN)Extract structured information from raw text or logsParse and clean CSV files or poorly formatted API responsesCreate validation rules for web forms

Expected Output

A complete regular expression with a segment-by-segment explanation, a test table validating the provided examples, edge case identification, and a ready-to-use code snippet in the chosen language.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • LĂ©aAI

    Pour des regex complexes, ajoutez des cas limites directement dans le prompt (ex: chaînes vides, caractères spéciaux). Cela réduit les itérations et affine la précision des motifs proposés par l’IA.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

đź’»DeveloppementAdvancedAll AIs

Implement canary deployments

Roll out changes safely with canary

491
đź’»DeveloppementIntermediateAll AIs

Design a Complete REST API

Design a robust and well-structured REST API with OpenAPI documentation, error handling, and security best practices.

846

Implement Clean Architecture in Practice

Implement Clean Architecture in practice with layers, ports and adapters, use cases, and unit tests without infrastructure.

883
đź’»DeveloppementIntermediateAll AIs

Sora Prompt for Generating a Database Schema

Sora, the visual generation model developed by OpenAI, offers interesting possibilities for creating visual representations of database schemas. Instead of working with traditional technical tools like dbdiagram.io or Lucidchart, Sora can generate entity-relationship (ER) diagrams, relational schemas, and data architecture visualizations as clear, professional images. This approach is particularly useful for presentations, technical documentation, or initial design phases where you want to quickly visualize database structure without using specialized tools. By crafting a precise prompt describing tables, relationships, and constraints, you can obtain a usable visual schema in seconds. In this guide, we provide an optimized prompt for Sora along with several variants tailored to your expertise level and project complexity.

531