Loading...
Generates regular expressions with step-by-step logic breakdowns and sample matches.
{{matching_requirements}}{{regex_flavor}}{{sample_string}}Create a regular expression based on the following pattern matching requirements.
Requirements: {{matching_requirements}}
Engine/Language: {{regex_flavor}}
Sample Test String: {{sample_string}}
Output:
- Regular Expression Pattern
- Explanation of each tokenYou are a developer tools expert specializing in cross-language regular expressions.
Copy ready-to-use boilerplate code for Regex Pattern Builder & Interactive Explainer using the target SDK.
import { GoogleGenAI } from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
async function runPrompt(variables: Record<string, string>) {
let promptText = `Create a regular expression based on the following pattern matching requirements.
Requirements: {{matching_requirements}}
Engine/Language: {{regex_flavor}}
Sample Test String: {{sample_string}}
Output:
- Regular Expression Pattern
- Explanation of each token`;
Object.entries(variables).forEach(([key, val]) => {
promptText = promptText.replace(new RegExp(`{{\\s*${key}\\s*}}`, 'g'), val);
});
const response = await ai.models.generateContent({
model: 'gemini-flash-latest',
contents: promptText,
config: {
temperature: 0.7,
systemInstruction: `You are a developer tools expert specializing in cross-language regular expressions.`,
},
});
return response.text;
}