Back to guide/Developer Tools

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.

copilot-promptspatternDescriptionvalidExamplesinvalidExamples
Edit View
Prompt
// 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

{{patternDescription}}{{validExamples}}{{invalidExamples}}{{flags}}{{regexName}}

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.