explaingit

yoav-lavi/melody

4,746RustAudience · developerComplexity · 2/5Setup · easy

TLDR

A small language that lets you write text-matching patterns in plain English words and compiles them into regular expressions automatically, so you never have to decode cryptic regex syntax again.

Mindmap

mindmap
  root((melody))
    What it does
      Compile English to regex
      Human-readable patterns
      ECMAScript regex output
    Syntax features
      Repetition counts
      Named capture groups
      Anchors and lookaheads
      Character classes
    How to use
      CLI tool
      Interactive REPL
      Browser playground
    Installation
      Cargo
      Homebrew
      Arch AUR
      NixOS
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

Write a readable Melody pattern that matches version strings like 1.2.3 and compile it to a regex for use in JavaScript code.

USE CASE 2

Replace a hard-to-read existing regex in a codebase with Melody syntax that teammates can understand without regex expertise.

USE CASE 3

Use the Melody REPL to iteratively build and test a text-matching pattern without switching between tools.

USE CASE 4

Generate named capture groups from human-readable syntax to extract structured data like dates or email parts from text.

Tech stack

RustCargo

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

Melody is a small programming language that compiles into regular expressions. Regular expressions are patterns used to search for or validate text, but their syntax is famously hard to read. A pattern like ^v?(\d+)\.(\d+)\.(\d+)$ is difficult to understand at a glance. Melody lets you write the same pattern in plain words and then outputs the equivalent regular expression automatically. The syntax uses English-style keywords. To match one or more digits you write some of <digit>. To match exactly 16 repetitions of the text "na" you write 16 of "na". Named groups called captures let you label parts of a pattern: capture major { some of <digit>, } becomes a named capturing group in the output. The language supports all the usual regular expression concepts including optional parts, lazy matching, character classes, anchors for start and end of a string, and lookaheads. Each feature maps directly to a well-known regex construct. Melody targets ECMAScript regular expressions, which are the kind used in JavaScript and many other environments. The compiler is written in Rust. You can run it as a command-line tool, use an interactive REPL that compiles each line as you type, or try it in a browser-based playground without installing anything. Installation is available through Cargo (the Rust package manager), Homebrew on macOS and Linux, the Arch User Repository, and NixOS. Pre-built binaries for macOS are on the releases page. The project has a book with full documentation at a separate site. The repository is actively maintained with a public changelog. It was built to make regular expressions more approachable by letting developers write patterns that read almost like a description of what they want to match.

Copy-paste prompts

Prompt 1
Using Melody, write the syntax to match a semantic version string like 2.14.0 with named captures for major, minor, and patch, then show me the regex it compiles to.
Prompt 2
I have this regex and want to rewrite it in Melody so it is easier to read and maintain. Translate it to Melody syntax and explain each part: ^[\w.-]+@[\w.-]+\.[a-z]{2,}$
Prompt 3
Show me how to install Melody via Homebrew and use its REPL to build a pattern that captures the year, month, and day from a date string like 2024-03-15.
Prompt 4
Write Melody syntax to match a Markdown heading line that starts with one or more hash signs followed by a space and text, and explain what each keyword does.
Open on GitHub → Explain another repo

← yoav-lavi on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.