Skip to content

Latest commit

 

History

637 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Regex For Humans: the regex ^#[0-9A-Fa-f]{6}$ with the plain-English meaning of each fragment written under it

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 · हिन्दी · العربية · اردو

Write rules, get a regex

RulesJavaScript regex
start "#"
6 hex digits
end
/^#[0-9A-Fa-f]{6}$/u

✅ #12aBcF · #000000
❌ #123 · #G00000

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.

Six recipes in turn: each shows its rules, the compiled regex, the meaning under every fragment and what it matched in a sample

Read a regex back

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.

Name the parts you capture

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.

Install

npm install regex-for-humans@preview
import { 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'));  // true
printf 'start "ABC"\n3 digits\nend\n' | npx --yes --package=regex-for-humans@preview regex-for-humans --explain

Node.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.

The vocabulary at a glance

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.

34 recipes, ready to open

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.

Why you can trust the output

  • 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.

Releases

Packages

Contributors

Languages