Regex Test Case Generator
Generate comprehensive test cases for regular expressions
About this ToolHow it works, benefits & use casesTap to collapse
The Regex Test Case Generator inspects a regular expression and writes a runnable test suite around it for Jest, Vitest, or Mocha with Chai. Paste a pattern with or without delimiters — both /^[a-z]+$/gi and bare ^[a-z]+$ are accepted — and the generator recognises the kind of pattern (email, URL, phone number, digit-only, or generic) to produce sensible positive and negative cases. The output is split into "Should match" and "Should not match" describe blocks, each calling regex.test() and asserting true or false, with string inputs safely escaped. Turn on "Include Edge Cases" to add empty-string, special-character, and whitespace-only assertions. Common-pattern buttons preload tried-and-tested expressions for email, URL, phone, hex colour, and IP address so you can generate a suite without writing a regex yourself. Copy the generated test file or download it with a framework-appropriate name, then refine the cases for your exact pattern.
How to Use
- 1Select a Test Framework (Jest, Vitest, or Mocha + Chai) and toggle "Include Edge Cases" if you want them.
- 2Enter your regex in the pattern field — with delimiters and flags (/pattern/flags) or as a bare pattern.
- 3Or click a Common Patterns button (Email, URL, Phone, Hex Color, IP Address) to load a ready-made expression.
- 4Click "Generate Test Cases" to build the Should-match and Should-not-match describe blocks.
- 5Copy the generated suite or download it as a .test.js / .spec.js file and adjust cases for your pattern.
Key Benefits
- Accepts patterns with or without /delimiters/ and flags
- Detects email, URL, phone, and digit patterns to generate relevant inputs
- Splits output into "Should match" and "Should not match" describe blocks
- Optional edge cases for empty strings, special characters, and whitespace-only input
- Common-pattern presets for email, URL, phone, hex colour, and IP address
- String inputs are escaped so generated test literals stay valid
- Framework-aware import line and download file name for Jest, Vitest, or Mocha
Common Use Cases
- Generating a baseline test suite for a validation regex before refining it
- Documenting which inputs a pattern should and should not match
- Producing edge-case assertions to harden a fragile expression
- Creating a starting suite for a common pattern like email or IP from the presets
- Switching an existing regex suite between Jest, Vitest, and Mocha syntax
Options
Enter pattern with or without delimiters (e.g., /pattern/flags or pattern)
Jest test suite
Generated test cases will appear here...
Was this tool helpful?
Share Your Experience
Help others discover this tool!
Related tools
- Regex TesterTest and debug regular expressions
- Find and ReplaceFind and replace text with support for regex
- JSON Schema ⇄ Zod ConverterConvert JSON Schema to Zod and back — with strict mode for OpenAI/Anthropic structured outputs and function calling
- Package.json GeneratorBuild a complete package.json with framework presets, scripts, deps, exports map, engines, and live validation
- Custom Hook TesterAnalyze and test React hook implementations
- Console.log RemoverRemove console statements from your JavaScript code
It analyses the pattern text for tell-tale fragments. If it sees @ it produces email cases, http or :// gives URL cases, a long pattern with \d gives phone-number cases, and \d+ or [0-9] gives digit-only cases. Anything else falls back to generic cases (a basic match, a case-variation test that respects the i flag, and an empty string). This is heuristic, so for unusual patterns you should review and tweak the generated inputs.
Yes. The tool understands both forms: /^[a-z]+$/gi (slashes plus flags) and a bare ^[a-z]+$. When delimiters are present the flags are extracted and used — for example the i flag makes the generic "case variation" test expect a match. The pattern is embedded verbatim into the generated test as const regex = ...;.

