Working example + reusable specification

Regular Expression Tester AI Prompt

Build a safe browser regex tester with JavaScript flags, text-node highlighting, capture details, bounded results, and worker termination for expensive patterns.

Regular Expression Tester working browser example

01 / What it builds

A complete interaction, not a loose concept

Copy a complete AI coding prompt for a private regex tester with flags, match highlighting, captures, worker timeouts, responsive controls, and tests.

02 / Complete prompt

Copy the build specification

Project: Regular Expression Tester

Objective
Build a private browser tool that safely evaluates JavaScript regular expressions, highlights matches, explains captures, and remains responsive when a pattern is computationally expensive.

Functional Requirements
- Accept an editable pattern, test text, and independent controls for the g, i, m, s, u, and y flags.
- Evaluate automatically after a short debounce and provide an explicit Test action plus Ctrl+Enter or Cmd+Enter.
- Highlight non-empty matches without interpreting test content as HTML.
- List each match with its value, source index, numbered captures, and named captures when present.
- Handle zero-width matches without an infinite loop and limit displayed results to a documented maximum.
- Provide sample, clear, and copy-expression actions.

Technical Requirements
- Use semantic HTML, responsive CSS, vanilla JavaScript, native modules, and a Web Worker.
- Run every user expression inside a replaceable worker and terminate it after 300ms so catastrophic backtracking cannot freeze the main thread.
- Keep compilation, matching, capture extraction, Unicode-aware zero-width advancement, result limits, and input limits independent from DOM rendering.
- Render entered content with text nodes or textContent only. Never interpret patterns, matches, captures, or test text as HTML.
- Keep patterns and test text in memory only. Do not place them in URLs, localStorage, analytics, logs, or generated markup.

Accessibility and Responsive Behavior
- Give pattern, flags, and test text visible labels and connect syntax or timeout feedback to the pattern input.
- Announce result counts and errors, expose invalid patterns with aria-invalid, and preserve keyboard access for every action.
- Use explicit highlighted text and a separate match list so results do not depend on color alone.
- Provide visible focus, 44px minimum targets, reduced-motion compatibility, and no horizontal overflow at 320px.

Acceptance Criteria
- Global and non-global patterns honor their selected JavaScript flags and report correct source indices.
- Numbered and named captures preserve unmatched values explicitly.
- Invalid syntax produces an error and no stale match list.
- Zero-width global matches advance safely; result lists stop at 1,000 entries.
- A pathological pattern is terminated after 300ms while the page remains interactive.
- Automated tests cover syntax, flags, captures, Unicode-safe zero-width matches, limits, worker timeout, highlighting, clearing, privacy, and mobile layout.

Deliverables
- The complete tester as the primary experience, not a landing page.
- Pure evaluation logic, a dedicated worker, a browser controller, and focused automated tests.
- No backend, account, runtime dependency, persistence, or transmission of pattern or test content.

Provided by www.my-ai-prompts.com