explaingit

francisrstokes/super-expressive

4,621JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A JavaScript library that lets you build regular expressions by chaining readable method names like .optional and .exactly instead of writing dense symbol-filled regex syntax.

Mindmap

mindmap
  root((repo))
    What It Does
      Builds regex patterns
      Plain English methods
      Converts to JS regex
    API Style
      Method chaining
      Readable names
      Helpful error messages
    Features
      Reusable sub-patterns
      TypeScript support
      Zero dependencies
    Other Languages
      PHP port
      Ruby port
      Python port
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Replace a hard-to-read regex in your codebase with a readable super-expressive method chain that your teammates can understand.

USE CASE 2

Define a reusable sub-pattern for email or URL validation and compose it into multiple larger form validators.

USE CASE 3

Port a JavaScript regex to PHP or Python using one of the community-contributed super-expressive language ports.

Tech stack

JavaScriptTypeScript

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

Super Expressive is a JavaScript library that lets you build regular expressions by chaining plain-English method names instead of writing the terse symbol-heavy syntax that regular expressions normally require. Regular expressions are patterns used in code to find, match, or validate text, but their compact notation is notoriously hard to read and remember. This library offers an alternative way to write them that is easier to understand and review. Instead of writing something like /^(?:0x)?([A-Fa-f0-9]{4})$/, you chain methods like .startOfInput, .optional.string('0x'), .exactly(4).anyOf, and .endOfInput to describe the same pattern step by step. The resulting object can be converted to a standard JavaScript regex at the end, so it works with everything that already uses regular expressions. The library has no dependencies and weighs less than 4kb. The API is designed to be discoverable: method names describe what they do in plain terms, order follows how you would read the rule in English, and the library gives helpful error messages if you chain something incorrectly. You can also define reusable sub-patterns and compose them into larger expressions, which is useful when the same matching rule appears in multiple places. The library includes full TypeScript support and has been ported to PHP, Ruby, and Python by community contributors. A browser-based playground is available for testing patterns interactively without writing any code. The README covers the full API with short code examples for every method, including flags like case-insensitive matching, multiline mode, and Unicode support.

Copy-paste prompts

Prompt 1
Using super-expressive, write a pattern that matches a hex color code like #A1B2C3 or the shorthand #fff.
Prompt 2
Convert this regex to super-expressive so it is easier to read and maintain: /^[\w.-]+@[\w.-]+\.[a-z]{2,6}$/i
Prompt 3
Show me how to define a reusable named sub-pattern in super-expressive and reference it multiple times in one expression.
Prompt 4
Generate a super-expressive chain that matches a US phone number in formats like 123-456-7890 or 123 456 7890 or 1234567890.
Open on GitHub → Explain another repo

← francisrstokes on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.