Skip to content

builtbyzero/regex-plain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

regex-plain

Explain any regex in plain English. No more squinting at ^[a-z0-9._%+-]+@….

$ npx regex-plain "/^[a-z]+$/i"

Pattern:  /^[a-z]+$/i
Meaning:  Matches a string that, from start to end, contains:
          any character in: a–z, repeated one or more times

Flags:
  i — case-insensitive

Free tier. Pro tier at $9 → https://buy.stripe.com/dRm9AM8S29ZVcbL4k6d3i07

Install

# one-shot, no install
npx regex-plain "/your-regex-here/flags"

# or install globally
npm install -g regex-plain
regex-plain "/your-regex-here/flags"

Requires Node.js 18 or newer.

Usage

regex-plain "/pattern/flags"           # explain a regex
regex-plain "/pattern/" --pro          # add match examples + pitfall detection
regex-plain "/pattern/" --json         # machine-readable JSON
regex-plain "/pattern/" --no-color     # disable ANSI colors
regex-plain --help                     # full help
regex-plain --version                  # version

Options

  • --pro — run Pro analysis (match examples, pitfalls, named groups, flag notes)
  • --json — emit JSON (no colors, no upsell); combines free + pro when both flags set
  • --no-color — disable ANSI colors (also via NO_COLOR=1 env var)

Colors are auto-disabled when stdout is not a TTY.

Inputs accepted:

  • "/pattern/flags" — full regex literal
  • "pattern" — raw pattern, no flags
  • "pattern/flags" — leading slash optional

Always quote the regex so your shell doesn't eat the special characters.

Programmatic API

import { explain, formatExplanation } from 'regex-plain';

const result = explain('/^\\d{3}-\\d{4}$/');
console.log(formatExplanation(result));
// →   { pattern, flags, opening, meaning: [...], flagsDescribed: [...],
//       namedGroups: [...], numberedGroups: [...] }

Free vs Pro

Feature Free Pro ($9)
Plain-English explanation of the pattern
Flags decoded
Match examples (strings that match/don't)
Named capture group documentation
Flag interaction warnings
Pitfall detection (catastrophic backtracking, etc.)

Get Pro: https://buy.stripe.com/dRm9AM8S29ZVcbL4k6d3i07

How it works

Parses the regex with regexp-tree into an AST, then walks the tree and emits human-readable descriptions for each node. No LLM. No hallucinated explanations. If a feature is too gnarly to describe cleanly, regex-plain says so and points you at regex101.com rather than guessing.

Development

git clone https://github.com/builtbyzero/regex-plain.git
cd regex-plain
npm install
npm test          # 41 tests, zero dev deps
node src/cli.js "/^[a-z]+$/i"

License

MIT © builtbyzero — https://builtbyzero.com

About

Explain any regex in plain English. Show what it matches and why.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors