๐ Human-Regex: Write Readable Regular Expressions Like English


Created by Ridwan Ajibola
// Before: Cryptic regex for password validation
const passwordRegex = /^(?=.*\d)(?=.*[!@#$%^&*])(?=.*[a-zA-Z]).{8,}$/;
// After: Human-readable with human-regex
const humanPasswordRegex = createRegex()
.startAnchor()
.hasDigit() // (?=.*\d)
.hasSpecialChar() // (?=.*[!@#$%^&*])
.hasLetter() // (?=.*[a-zA-Z])
.anyCharacter() // .
.atLeast(8) // {8,}
.endAnchor()
.toRegExp();
Why I Built This
Regex is powerful, but letโs be honest: patterns like /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/
look like someone fell asleep on their keyboard. When I first learned JavaScript, regex was my #1 frustration โ and every developer I asked shared this pain.
So I asked: What if we could write regex in plain English?
Human-Regex was born, created by Ridwan Ajibola, a utility library that turns regex patterns into chainable, self-documenting code.
How It Works
Traditional Regex โ Human-Regex
Traditional Regex | Human-Regex Equivalent |
/\d/ | .digit() |
/[a-zA-Z]/ | .letter() |
/(?=.*\d)/ | .hasDigit() |
^ / $ | .startAnchor() / .endAnchor() |
const emailRegex = createRegex()
.startAnchor()
.word().oneOrMore() // [a-zA-Z0-9_]+
.literal('@') // @
.word().oneOrMore() // [a-zA-Z0-9_]+
.literal('.') // .
.letter().atLeast(2) // [a-zA-Z]{2,}
.endAnchor()
.toRegExp();
No more guessing what [a-zA-Z0-9_]
or {2,}
means. The code explains itself.
Key Features
โ
Readable Syntax
Methods like .hasDigit()
and .startAnchor()
make patterns self-documenting.
โ
Chainable Design
Build complex patterns step-by-step, just like writing a sentence.
โ
Lightweight
Just 1.0 kB gzipped. (1.4kB new version)
โ
Open Source
MIT licensed. Contributions welcome!
Get Started in 60 Seconds
Install the library:
npm install human-regex
Build your first regex:
const urlRegex = createRegex()
.startAnchor()
.protocol() // https?://
.www().optional() // (www\.)?
.word().oneOrMore()
.literal('.')
.tld() // com|org|net
.toRegExp();
More Examples
For additional usage examples, take a look at the test file in the repository.
Why This Matters
Onboarding: New developers understand regex logic at a glance.
Maintenance: No more regex archaeology to update old code.
Collaboration: Teams spend less time decoding patterns.
Join the Movement
Regex doesnโt have to be scary. Try Human Regex and:
โญ Star the GitHub repo โ it really helps! ๐
๐ Report bugs or request features
๐ก Contribute code or documentation
Letโs make regex accessible to everyone!
Don't forget to connect with me on LinkedIn. I'm currently exploring new opportunities, so if you have any leads or ideas, feel free to reach out!
Subscribe to my newsletter
Read articles from Ridwan Ajibola directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Ridwan Ajibola
Ridwan Ajibola
A creative Front End developer with 6 years of experience developing, testing and deploying high-quality, scalable web applications and mobile applications.