Regex Builder Comment
Providing both valid and invalid examples lets Copilot generate a precise regex instead of an overly broad one. Starting the const declaration on the next line triggers inline completion with the full pattern.
// Build a regex that matches {{patternDescription}} // Valid examples: {{validExamples}} // Invalid examples (should NOT match): {{invalidExamples}} // Flags: {{flags}} // Return as a named const with a JSDoc comment explaining the pattern const {{regexName}}: RegExp =
Variables to customize
Why this prompt works
Providing both valid and invalid examples lets Copilot generate a precise regex instead of an overly broad one. Starting the const declaration on the next line triggers inline completion with the full pattern.
Save this prompt to your library
Organize, version, and access your best prompts across ChatGPT, Claude, and Cursor.
Related prompts
Get thorough code reviews with actionable feedback tailored to your language, framework, and standards.
Context-Aware Code CompletionProviding the surrounding code and project context lets the model match existing patterns exactly. The constraint against modifying existing code prevents unwanted side effects.
Inline Code SuggestionConstraining suggestions to match existing style and scope produces insertions that feel native to the codebase. The 'no explanation' rule mimics real inline completion behavior.
Code ExplanationThe audience level parameter adjusts complexity automatically. Requiring a usage example ensures the explanation is practical, not just theoretical.