Text Analysis & GenerationText TransformationCoding
Regex Builder from Plain English
Turn plain-English pattern requirements into a flavor-specific regex, returning only Pattern, Flags, and brief Explanation bullets, honoring user constraints and safe defaults (anchors, no DOTALL/multiline).
Prompt Content
Act as a senior regex engineer. Create a regex that matches the described pattern and provide a brief explanation.
Pattern description:
<pattern-description>
Pattern Description
</pattern-description>
Rules/constraints:
<rules-constraints>
Rules Constraints
</rules-constraints>
Target regex flavor: Regex Flavor
1) Build one regex valid for the stated flavor using only supported syntax.
2) Apply these defaults unless overridden:
• Anchor to the entire string (^...$)
• Case-sensitive
• No DOTALL, no multiline
• Prefer non-capturing groups unless capturing is required
• Avoid catastrophic backtracking; use precise quantifiers and atomic/possessive forms only if the flavor supports them
3) Use clear, maintainable structure (grouping, character classes, and lookarounds only when needed).
4) Return only the following, in order:
Pattern: <regex without delimiters>
Flags: <letters or none>
Explanation:
• <3-6 brief bullets explaining key parts>
<example>
Input
Pattern description: Match US phone numbers like (123) 456-7890 or 123-456-7890; optional country code +1; separators space or dash; no extensions.
Rules/constraints: Entire string; allow optional parentheses around area code; disallow letters; prefer non-capturing groups; case-insensitive not needed.
Target regex flavor: JavaScript
Expected output
Pattern: ^(?:\+1[ -]?)?(?:\(\d{3}\)|\d{3})[ -]?\d{3}[ -]?\d{4}$
Flags: none
Explanation:
• ^ and $ anchor the whole string
• (?:...) groups alternatives without capturing
• \d{3} and \d{4} enforce digit counts
• Optional +1 and separators handled
• Disallows letters and extensions
</example>
Variables
- Pattern Description
- Plain-English description of what must match; include allowed/forbidden parts and examples if useful.
- Example: Emails with subdomains; username may include dots and plus; domain must be example.com or a subdomain of it; TLD .com only.
- Rules Constraints
- Specific must/avoid rules (anchors, case-sensitivity, Unicode, multiline, DOTALL, groups, lookarounds, lengths, separators, permitted chars).
- Example: Match entire string; case-insensitive; allow Unicode letters; no lookbehind; use named groups for user and domain; forbid consecutive dots.
- Regex Flavor
- Target regex engine/flavor.
- Example: JavaScript (ECMAScript)