Write regex in plain English. Read any regex the same way.

Regex For Humans compiles short English rules into a native JavaScript regex, and translates a regex back into rules. Every fragment carries its meaning, so you see exactly what a pattern does before you ship it.

npm install regex-for-humans@previewLibrary + CLI · Node.js 22+Get the npm preview ↗

Example

Examples to gloss
regex^#[0-9A-Fa-f]{6}$
meansstart"#"6 hex digitsend
takes
Six hex digits after #, in either letter case. Only #RRGGBB; no shorthand, alpha or other CSS color forms.

Not checked

matches #12aBcFno match #123

Demo limit: 80 UTF-16 code units. Longer input is kept but cannot be tested. The workshop accepts up to 2,048.

Rules
start "#"
6 hex digits
end
JavaScript regex
/^#[0-9A-Fa-f]{6}$/u
Edit this in the workshop ↗

One rule, one fragment. In both directions.

Each rule line compiles to one piece of the regex, in order, with nothing hidden. Read the other way, a supported regex comes back as the same kind of rules, ready to edit.

Rules and regex, aligned Four rules, start, the text INV-, between 2 and 6 digits, and end, each joined by a line to the regex fragment it compiles to: caret, INV-, backslash d with 2 to 6, and dollar. compile turns rules into the regex; regexToRules reads it back. start "INV-" between 2 and 6 digits end ^INV-\d{2,6}$ compile() ↓ ↑ regexToRules() Rules and regex, aligned: start is caret, "INV-" is INV-, between 2 and 6 digits is backslash d 2 to 6, end is dollar. start "INV-" between 2 and 6 digits end ^ INV- \d{2,6} $ compile() → ← regexToRules()
  1. Deterministic. The same rules always give the same regex. There is no AI and no network call.
  2. Native. The output is an ordinary RegExp with the u flag. Nothing runs at match time but the engine.
  3. Honest about limits. Syntax outside the supported subset is refused with a line, a column and a fix, never dropped quietly.

Name the parts you capture.

A named capture is a native JavaScript group. Write it as a rule, then read the field by name.

Rules
start
capture "year" {
  4 digits
}
"-"
capture "month" {
  2 digits
}
"-"
capture "day" {
  2 digits
}
end
JavaScript regex
/^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/u

Input 2026-10-10

year
2026
month
10
day
10

This checks the date's shape. For real months and days, use the calendar date example. Nested groups and references ↗

34 worked examples.

Each one opens in the workshop with its rules, regex and test strings that must and must not match. Every note says what the pattern does not check.

IDs and codes

  1. (1)Give IDs a shape/^ABC\d{3}$/uABC123A prefix + exactly three digits.
  2. (2)Shape an invoice ID/^INV-\d{2,6}$/uINV-1234INV- + 2–6 digits. Verify records separately.
  3. (3)Shape a username/^[A-Za-z]\w{2,15}$/uAlice_73–16 characters; ASCII letter first.
  4. (4)Shape a product code/^[A-Z]{2}-[a-z]{3}-\d{4}$/uAB-rgb-04202 uppercase + 3 lowercase letters + 4 digits.
  5. (5)Find your color/^#[0-9A-Fa-f]{6}$/u#12aBcFSix hexadecimal digits after #.
  6. (6)Shape a MAC address/^[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}$/u00:1A:2B:3C:4D:5ESix colon-separated hex pairs. Check allocation separately.
  7. (7)Shape a UUID/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/u8–4–4–4–12 hex digitsEither letter case. Check version, variant and uniqueness separately.
  8. (8)Match a Git object hash shape/^(?:[0-9A-Fa-f]{40}|[0-9A-Fa-f]{64})$/u40 / 64 hex digitsHex shape only. Verify repository object existence separately.
  9. (9)Try an optional prefix/^\+?\d{7,15}$/u+33123456789Optional + and 7–15 digits. Check number validity separately.

Dates, times and versions

  1. (10)Check a date shape/^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/u2026-09-30YYYY-MM-DD. Calendar checks are separate.
  2. (11)Validate a calendar date/^(?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>0[1-9]|[12]\d|3[01])$/u2026-09-30Month 01–12, day 01–31. Month lengths are not checked.
  3. (12)Check a time shape/^\d{2}:\d{2}$/u09:30HH:MM. Check hour and minute ranges separately.
  4. (13)Validate a 24-hour time/^(?:[01]\d|2[0-3]):[0-5]\d$/u23:5900:00 to 23:59. Rejects 24:00.
  5. (14)Match a UTC timestamp shape/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?Z$/u2026-10-11T09:30:00ZOptional fractions and Z. Calendar and range checks stay separate.
  6. (15)Spot a version shape/^\d+\.\d+\.\d+$/u1.2.3Three numeric parts. Not full SemVer.
  7. (16)Validate SemVer 2.0 syntax/^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[A-Za-z\-][A-Za-z\d\-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z\-][A-Za-z\d\-]*))*))?(?:\+(?<build>[A-Za-z\d\-]+(?:\.[A-Za-z\d\-]+)*))?$/u1.2.3-alpha.1+001Core, prerelease and build syntax; no precedence comparison.
  8. (17)Shape an IPv4 address/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/u192.0.2.42Four 1–3 digit groups. Not a 0–255 range check.
  9. (18)Validate an IPv4 address/^(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)){3}$/u192.168.1.1Each number 0–255, no leading zeros.

Text, files and web

  1. (19)Match a lowercase slug/^[a-z\d]+(?:-[a-z\d]+)*$/uhello-worldLowercase ASCII words separated by single hyphens.
  2. (20)Shape a text filename/^[^\/\\\u{0}\n\r\u{2028}\u{2029}]{1,64}\.txt$/ureport.txtBound a Unicode stem and exclude separators. Filesystem rules are separate.
  3. (21)Find a file extension/\.(?<extension>txt|md|json)$/uREADME.mdSearch txt, md or json suffixes; filename validity stays separate.
  4. (22)Match a simple HTTPS URL shape/^https:\/\/[A-Za-z\d]+(?:[\-.][A-Za-z\d]+)*(?:\/\S*)?$/uhttps://example.comA small ASCII-host subset, not complete URL validation.
  5. (23)Match a Markdown heading fragment/^#{1,6} (?<heading>[^\r\n\u{2028}\u{2029}]+)$/u# HelloOne to six # characters and a title, not a Markdown parser.
  6. (24)Keep characters out/^[^abcd]*$/utext without: a, bChoose which characters to exclude.
  7. (25)Read between lines/^.*\d{3}$/muitem 123A line ending in at least three digits.
  8. (26)Match Unicode letters and marks/^\p{L}[\p{L}\p{M}]*$/uالعربية / اردوNative Unicode letters and marks; no normalization or grapheme counting.

Captures, references and logs

  1. (27)Extract a simple header field/^(?<field>[A-Za-z\d!#$%&'*+\-.\^_`|~]+): (?<value>[^\r\n\u{0}\u{2028}\u{2029}]+)$/uContent-Type: application/jsonNamed field and single-line value, not a full HTTP parser.
  2. (28)Extract named fields from a log fragment/(?<level>INFO|WARN|ERROR) code=(?<code>\d{3})/uINFO code=200Extract level and code from a searched log fragment.
  3. (29)Match two repeated words/^(?<word>[A-Za-z]+) \k<word>$/uhello helloA named reference to the preceding ASCII word.
  4. (30)Detect adjacent duplicate tokens/^(?<token>\w{1,16}),\k<token>$/uitem,itemOne adjacent comma-separated pair; not whole-list deduplication.
  5. (31)Search and replace a typo/\b(?<word>teh)\b/uteh → thePreloaded exact spans, captures and non-global replacement checks.
  6. (32)Read an artifact manifest/^incoming\/(?:nightly\/)?[^\/\\\u{0}\n\r\u{2028}\u{2029}]{1,32}\/v\d{1,3}\.\d{1,3}\.\d{1,3}\/linux-arm64\/widget_\d{8}_[0-9A-Fa-f]{8}\.tar\.gz\t[0-9A-Fa-f]{64}\t\d{1,12}$/upath → hash → size19 rules, optional nightly/ directory and literal tabs. Nine examples ready to test.
  7. (33)Read an access log/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} - [^ \n\r\u{2028}\u{2029}]{1,32} \[\d{2}\/[A-Za-z]{3}\/\d{4}:\d{2}:\d{2}:\d{2} [+\-]\d{4}\] "[A-Z]{3,7} [^ "\n\r\u{2028}\u{2029}]{1,200} HTTP\/\d\.\d" \d{3} \d{1,10} "[^"\n\r\u{2028}\u{2029}]{1,200}" "[^"\n\r\u{2028}\u{2029}]{1,200}"$/urequest → status → size43 rules, bounded fields and quoted text. Eight examples ready to test.
  8. (34)Read a telemetry event/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z level=[A-Z]{4,5} service=\w{3,30} trace=[0-9A-Fa-f]{32} span=[0-9A-Fa-f]{16} method=[A-Z]{3,7} route=[^ \n\r\u{2028}\u{2029}]{1,200} status=\d{3} bytes=\d{1,10} duration=\d{1,7}\.\d{3}ms lane=[ABC]?(?: retry=true)?$/utrace → duration → lane38 rules and independent optional values. Nine examples ready to test.

Ready for bigger patterns? Explore four complex examples ↗: access logs, telemetry, artifact manifests and multiline documents, with every fragment explained.

The workshop

Search 34 recipes or paste a regex to translate. Edit rules with completions, read each fragment's meaning, and keep strings that must match or must not. Everything runs in your browser; share a snapshot by link when you want to.

Open the workshop
Regex For Humans workshop showing its recipe list, a generated regex, explanations, and passing examples.

A small vocabulary with exact meanings.

Every instruction maps to one documented regex fragment. An unknown word fails with a line, a column and a repair hint.

Read the syntax guide ↗

Raw regex is not rule text; a supported subset translates back into rules. Groups and ordered alternatives are supported; forward and open capture references are rejected.

start / end^ / $
3 digits\d{3}
between 2 and 6 digits\d{2,6}
letters[A-Za-z]+
lowercase letters / uppercase letters[a-z]+ / [A-Z]+
6 hex digits[0-9A-Fa-f]{6}
"hello"hello
one of: a, b[ab]
text without: a, b[^ab]*
any text.*

Use it in your own project.

The library, the CLI and the workshop share one parser and one compiler. No runtime dependencies.

JavaScript and TypeScript

Compile rules, build a native regex and read each fragment's explanation. ESM, with type declarations.

After installing the preview
import { compile, toRegExp } from 'regex-for-humans';

const result = compile('start 3 digits\nend');
toRegExp(result).test('123'); // true
console.log(result.segments);

In the terminal

Read rules from a file or stdin, print the explanation of every fragment, or translate a regex back with --reverse.

Node.js 22+ · npm preview
printf 'start "ABC"\n3 digits\nend\n' | npx --yes --package=regex-for-humans@preview regex-for-humans --explain
/^ABC\d{3}$/u
1:1  ^  Input start.
1:7  ABC  Literal text "ABC".
2:1  \d{3}  Exactly 3 digits (0–9).
3:1  $  Input end.

--json --reverse --flags --ignore-case --dot-all --target

The guide, in ten languages.

Including Arabic and Urdu, right to left. The rule words stay English, so every example runs through the same compiler.

Questions

Does it understand any English sentence?

It uses a fixed, documented vocabulary. Unknown instructions receive a line, column and repair hint. There is no AI interpretation or remote prompt.

Can I import every regex?

The translator accepts the documented native JavaScript subset: groups, captures, ordered alternatives, backward references, lazy repetition, lookahead/lookbehind, word boundaries, Unicode properties/classes and v-mode strings and nested sets. Empty sets require v mode. Forward/open references, empty u-mode classes and other-engine constructs receive diagnostics. Unsupported syntax is never silently removed.

Can flags apply to just one group?

Use group with flags "i" { to ignore case inside one block; closing it restores the enclosing options. Local i/m/s flags also work with nested groups, captures and reverse translation. They require a compatible native engine: verified browser Unicode modes pass, while tested Node 22/25/26 editions receive an explicit unsupported-feature error. Cached source cannot bypass that check. Read the syntax and runtime limits.

Are my test strings sent anywhere?

The workshop matches in your browser's isolated worker. Rules and examples stay local. The page and its static assets are served by the hosting provider; no application backend receives your matching inputs.

Does a passing example prove a regex is safe?

Examples establish selected behavior. The workshop bounds input and terminates a worker after 1,200 ms. A regex copied into another application needs that application's own execution safeguards.

Which version should I use?

npm 0.1.0-dev.13 is a development preview of the library and CLI; it needs Node.js 22 or newer. The workshop on this site runs the same compiler in your browser. There is no stable release yet, so pin the exact preview version in a project.