Coding
AI Prompt for Converting Regex Flavors
Convert regex between languages with this AI prompt: flavor-by-flavor translation, incompatibility warnings, and verified equivalent patterns.
The prompt
Role: You are a regex polyglot fluent in every major flavor's quirks and incompatibilities. Context: Converting from [FROM_FLAVOR] to [TO_FLAVOR]. Original pattern: [ORIGINAL_PATTERN] What it is used for: [USAGE_CONTEXT] Task: 1) Provide the equivalent pattern in [TO_FLAVOR]. 2) List every construct that differs between the flavors (lookbehind support, named group syntax, flag placement, escape rules) and how you translated each. 3) Flag anything with NO equivalent in [TO_FLAVOR] and provide the closest workaround. 4) Verify with 3 test strings that both patterns behave identically. Format: Converted pattern first, then the translation notes as a list, then incompatibility warnings, then the verification table. Ask the AI to produce a side-by-side test script that runs both patterns against the same inputs in their respective languages, so equivalence is proven by execution rather than by inspection. Constraints: Never silently drop features — if something cannot translate exactly, say so loudly and offer the workaround. Preserve the original's match semantics, not just its appearance.
Variables to fill in
Replace each [variable] in the prompt with your own details:
[FROM_FLAVOR] [TO_FLAVOR] [ORIGINAL_PATTERN] [USAGE_CONTEXT]
Example input
FROM=JavaScript, TO=Python, PATTERN=/\b(\w+)@([\w.]+)\.(\w{2,})\b/g, CONTEXT=extracting emails, NOTE=needs re module equivalent
How to use this prompt
Name both flavors exactly — PCRE, .NET, RE2, and Go all differ. Paste the original pattern untouched; even small edits change the meaning.
Tips for the best results
- Always check lookbehind support first — it is the most common incompatibility.
- Ask for the test strings to include your real data, not just toy examples.
- If the workaround is ugly, ask whether restructuring the code avoids regex entirely.
Frequently asked questions
Are all regex features portable?
It maps each construct and flags the ones with no direct equivalent, so nothing gets silently lost in translation.
Which regex features break most often in conversion?
Lookbehind assertions and named-group syntax differ the most between flavors. The prompt flags every incompatible construct before translating.