Melody
Melody is a language that compiles to regular expressions and aims to be more readable and maintainable
Install / Use
/learn @yoav-lavi/MelodyREADME
Examples
Note: these are for the currently supported syntax and may change
Batman Theme <sub><sup><a href="https://melody-playground.vercel.app?content=MTYlMjBvZiUyMCUyMm5hJTIyJTNCJTBBJTBBMiUyMG9mJTIwbWF0Y2glMjAlN0IlMEElMjAlMjAlM0NzcGFjZSUzRSUzQiUwQSUyMCUyMCUyMmJhdG1hbiUyMiUzQiUwQSU3RCUwQSUwQSUyRiUyRiUyMCVGMCU5RiVBNiU4NyVGMCU5RiVBNiVCOCVFMiU4MCU4RCVFMiU5OSU4MiVFRiVCOCU4Rg==">try in playground</a></sup></sub>
16 of "na";
2 of match {
<space>;
"batman";
}
// 🦇🦸♂️
Turns into
(?:na){16}(?: batman){2}
Twitter Hashtag <sub><sup><a href="https://melody-playground.vercel.app?content=JTIyJTIzJTIyJTNCJTBBc29tZSUyMG9mJTIwJTNDd29yZCUzRSUzQiUwQSUwQSUyRiUyRiUyMCUyM21lbG9keQ==">try in playground</a></sup></sub>
"#";
some of <word>;
// #melody
Turns into
#\w+
Introductory Courses <sub><sup><a href="https://melody-playground.vercel.app?content=c29tZSUyMG9mJTIwJTNDYWxwaGFiZXRpYyUzRSUzQiUwQSUzQ3NwYWNlJTNFJTNCJTBBJTIyMSUyMiUzQiUwQTIlMjBvZiUyMCUzQ2RpZ2l0JTNFJTNCJTBBJTBBJTJGJTJGJTIwY2xhc3NuYW1lJTIwMXh4">try in playground</a></sup></sub>
some of <alphabetic>;
<space>;
"1";
2 of <digit>;
// classname 1xx
Turns into
[a-zA-Z]+ 1\d{2}
Indented Code (2 spaces) <sub><sup><a href="https://melody-playground.vercel.app?content=c29tZSUyMG9mJTIwbWF0Y2glMjAlN0IlMEElMjAlMjAyJTIwb2YlMjAlM0NzcGFjZSUzRSUzQiUwQSU3RCUwQSUwQXNvbWUlMjBvZiUyMCUzQ2NoYXIlM0UlM0IlMEElMjIlM0IlMjIlM0IlMEElMEElMkYlMkYlMjBsZXQlMjB2YWx1ZSUyMCUzRCUyMDUlM0I=">try in playground</a></sup></sub>
some of match {
2 of <space>;
}
some of <char>;
";";
// let value = 5;
Turns into
(?: {2})+.+;
Semantic Versions <sub><sup><a href="https://melody-playground.vercel.app?content=JTNDc3RhcnQlM0UlM0IlMEElMEFvcHRpb24lMjBvZiUyMCUyMnYlMjIlM0IlMEElMEFjYXB0dXJlJTIwbWFqb3IlMjAlN0IlMEElMjAlMjBzb21lJTIwb2YlMjAlM0NkaWdpdCUzRSUzQiUwQSU3RCUwQSUwQSUyMi4lMjIlM0IlMEElMEFjYXB0dXJlJTIwbWlub3IlMjAlN0IlMEElMjAlMjBzb21lJTIwb2YlMjAlM0NkaWdpdCUzRSUzQiUwQSU3RCUwQSUwQSUyMi4lMjIlM0IlMEElMEFjYXB0dXJlJTIwcGF0Y2glMjAlN0IlMEElMjAlMjBzb21lJTIwb2YlMjAlM0NkaWdpdCUzRSUzQiUwQSU3RCUwQSUwQSUzQ2VuZCUzRSUzQiUwQSUwQSUyRiUyRiUyMHYxLjAuMA==">try in playground</a></sup></sub>
<start>;
option of "v";
capture major {
some of <digit>;
}
".";
capture minor {
some of <digit>;
}
".";
capture patch {
some of <digit>;
}
<end>;
// v1.0.0
Turns into
^v?(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)$
Playground
You can try Melody in your browser using the playground
Book
Read the book here
Install
Cargo
cargo install melody_cli
From Source
git clone https://github.com/yoav-lavi/melody.git
cd melody
cargo install --path crates/melody_cli
Binary
- macOS binaries (
aarch64andx86_64) can be downloaded from the release page
Community
-
Brew (macOS and Linux)
<details><summary>Installation instructions</summary>
</details>brew install melody -
Arch Linux (maintained by @ilai-deutel)
<details><summary>Installation instructions</summary>-
Installation with an AUR helper, for instance using
paru:paru -Syu melody -
Install manually with
makepkg:git clone https://aur.archlinux.org/melody.git cd melody makepkg -si
-
-
<details><summary>Installation instructions</summary>
-
Declarative installation using
/etc/nixos/configuration.nix:{ pkgs, ... }: { environment.systemPackages = with pkgs; [ melody ]; } -
Imperative installation using
nix-env:nix-env -iA nixos.melody
-
CLI Usage
USAGE:
melody [OPTIONS] [INPUT_FILE_PATH]
ARGS:
<INPUT_FILE_PATH> Read from a file
Use '-' and or pipe input to read from stdin
OPTIONS:
-f, --test-file <TEST_FILE>
Test the compiled regex against the contents of a file
--generate-completions <COMPLETIONS>
Outputs completions for the selected shell
To use, write the output to the appropriate location for your shell
-h, --help
Print help information
-n, --no-color
Print output with no color
-o, --output <OUTPUT_FILE_PATH>
Write to a file
-r, --repl
Start the Melody REPL
-t, --test <TEST>
Test the compiled regex against a string
-V, --version
Print version information
Changelog
See the changelog here or in the release page
Syntax
Quantifiers
... of- used to express a specific amount of a pattern. equivalent to regex{5}(assuming5 of ...)... to ... of- used to express an amount within a range of a pattern. equivalent to regex{5,9}(assuming5 to 9 of ...)over ... of- used to express more than an amount of a pattern. equivalent to regex{6,}(assumingover 5 of ...)some of- used to express 1 or more of a pattern. equivalent to regex+any of- used to express 0 or more of a pattern. equivalent to regex*option of- used to express 0 or 1 of a pattern. equivalent to regex?
All quantifiers can be preceded by lazy to match the least amount of characters rather than the most characters (greedy). Equivalent to regex +?, *?, etc.
Symbols
<char>- matches any single character. equivalent to regex.<space>- matches a space character. equivalent to regex<whitespace>- matches any kind of whitespace character. equivalent to regex\sor[ \t\n\v\f\r]<newline>- matches a newline character. equivalent to regex\n<tab>- matches a tab character. equivalent to regex\t<return>- matches a carriage return character. equivalent to regex\r<feed>- matches a form feed character. equivalent to regex\f<null>- matches a null characther. equivalent to regex\0<digit>- matches any single digit. equivalent to regex\dor[0-9]<vertical>- matches a vertical tab character. equivalent to regex\v<word>- matches a word character (any latin letter, any digit or an underscore). equivalent to regex\wor[a-zA-Z0-9_]<alphabetic>- matches any single latin letter. equivalent to regex[a-zA-Z]<alphanumeric>- matches any single latin letter or any single digit. equivalent to regex[a-zA-Z0-9]<boundary>- Matches a character between a character matched by<word>and a character not matched by<word>without consuming the character. equivalent to regex\b<backspace>- matches a backspace control character. equivalent to regex[\b]
All symbols can be preceeded with not to match any character other than the symbol
Special Symbols
<start>- matches the start of the string. equivalent to regex^<end>- matches the end of the string. equivalent to regex$
Unicode Categories
Note: these are not supported when testing in the CLI (-t or -f) as the regex engine used does not support unicode categories. These require using the u flag.
<category::letter>- any kind of letter from any language<category::lowercase_letter>- a lowercase letter that has an uppercase variant<category::uppercase_letter>- an uppercase letter that has a lowercase variant.<category::titlecase_letter>- a letter that appears at the start of a word when only the first letter of the word is capitalized<category::cased_letter>- a letter that exists in lowercase and uppercase variants<category::modifier_letter>- a special character that is used like a letter<category::other_letter>- a letter or ideograph that does not have lowercase and uppercase variants
<category::mark>- a character intended to be combined with another character (e.g. accents, umlauts,
Related Skills
himalaya
333.3kCLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).
node-connect
333.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
82.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
coding-agent
333.3kDelegate coding tasks to Codex, Claude Code, or Pi agents via background process
