Write regex in plain English. Read any regex the same way.
Short English rules compile to a native JavaScript RegExp, one visible fragment per rule. Paste a regex and get the rules back.
Try the workshop · Website · npm preview · Syntax
English · 简体中文 · Español · Français · Português do Brasil · 日本語 · Deutsch · हिन्दी · العربية · اردو
| Rules | JavaScript regex |
|---|---|
|
/^#[0-9A-Fa-f]{6}$/u✅ |
Each line has one documented meaning and adds one fragment to the regex, in order. The output is the regex you would write by hand: ? rather than {0,1}, no extra groups. An unknown phrase stops with its line, column and a suggested fix.
Inherited a pattern nobody can read? regexToRules turns a supported regex into rules you can edit, and those rules compile back to the same regex.
import { regexToRules } from 'regex-for-humans';
regexToRules(/^[A-Z]{2}-\d{4}$/u).rules;start
2 uppercase letter
"-"
4 digit
end
The website glosses any pasted regex in place. Unsupported syntax is refused with its position, never dropped quietly.
start
capture "year" {
4 digits
}
"-"
capture "month" {
2 digits
}
"-"
capture "day" {
2 digits
}
end
toRegExp(compile(rules)).exec('2026-10-10').groups;
// { year: '2026', month: '10', day: '10' }Captures are native JavaScript groups. Write same as capture "year" to require the same text again.
npm install regex-for-humans@previewimport { compile, toRegExp } from 'regex-for-humans';
const result = compile('start\n3 digits\nend');
console.log(result.source); // ^\d{3}$
console.log(toRegExp(result).test('123')); // trueprintf 'start "ABC"\n3 digits\nend\n' | npx --yes --package=regex-for-humans@preview regex-for-humans --explainNode.js 22+, no runtime dependencies, ESM with TypeScript declarations. The library, the command line and the workshop share one compiler. This is a preview (0.1.0-dev.13); the workshop needs no install.
| Say this | Get this |
|---|---|
start · end |
^ · $ |
3 digits · digits |
\d{3} · \d+ |
between 2 and 4 letters |
[A-Za-z]{2,4} |
optional "-" |
-? |
one of: a, b |
[ab] |
either { "INFO" "WARN" } |
(?:INFO|WARN) |
capture "id" { … } |
(?<id>…) |
not followed by { "x" } |
(?!x) |
Blocks such as either { … } put one rule per line inside the braces. The language guide covers every rule, flag, Unicode class, lookaround and limit.
| Recipe | What it checks |
|---|---|
| Validate a calendar date | Month 01–12, day 01–31, captured as year, month and day |
| Validate an IPv4 address | Four numbers from 0 to 255, no leading zeros |
| Validate a 24-hour time | 00:00 to 23:59 |
| Validate SemVer 2.0 syntax | Core, prerelease and build parts |
| Extract named fields from a log fragment | Level and code, by name |
| Match two repeated words | A word, then the same word again |
Every recipe comes with examples that must and must not match, and a note on what it does not check. See all 34 recipes and four complex examples with 35 accepted/rejected cases.
- Deterministic. A parser, not a model: the same rules always give the same regex. No AI, no network, no telemetry.
- Native. The output is an ordinary
RegExp; nothing runs at match time but the engine. Exports to Python, Rust, Go, Java, C#, PHP and Ruby are compared against those engines. - Honest about limits. Recipes say what they do not check. The workshop runs your examples in a time-limited worker; a copied regex needs its own safeguards (security model).
- Tested. Every recipe and every example in this README is recompiled by the test suite (testing).
Architecture · Compatibility · Contributing · Changelog · Security · MIT
If a rule here saved you some squinting, a ⭐ helps other developers find it.