Regex was a mistake. Just like your ex.
Write regex without the tears or confusion.
A human-readable regex builder for JavaScript & TypeScript.
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/Your coworker asks what it does. You mass tears. You mass confusion. You mass quit.
import { email } from 'zeroreg/patterns'
email.test('hello@world.com') // trueOr build your own:
import { digit, optional } from 'zeroreg'
const phone = optional('+')
.then(digit(3))
.then('-')
.then(digit(3))
.then('-')
.then(digit(4))
phone.test('123-456-7890') // true
phone.toRegex() // /\+?\d{3}-\d{3}-\d{4}/npm install zeroreg| Function | Description | Regex |
|---|---|---|
digit(n?) |
Match digits | \d or \d{n} |
word() |
Word characters | \w |
letter() |
Letters only | [a-zA-Z] |
whitespace() |
Whitespace | \s |
any() |
Any character | . |
literal(str) |
Exact match | (escaped) |
charIn(chars) |
Match any in set | [...] |
charNotIn(chars) |
Match any NOT in set | [^...] |
| Method | Description |
|---|---|
.oneOrMore() |
1+ times |
.zeroOrMore() |
0+ times |
.optional() |
0 or 1 |
.times(n) |
Exactly n |
.between(min, max) |
Range |
.atLeast(n) |
n or more |
| Function | Description |
|---|---|
capture(pattern, name?) |
Capturing group |
group(pattern) |
Non-capturing group |
oneOf(...patterns) |
Match any of |
| Function | Description |
|---|---|
startOfLine() |
^ |
endOfLine() |
$ |
wordBoundary() |
\b |
| Method | Description |
|---|---|
.toRegex(flags?) |
Get native RegExp |
.test(str) |
Test string |
.match(str) |
Get matches |
.matchAll(str) |
Get all matches |
.replace(str, replacement) |
Replace matches |
import { email, url, phone, date, ipv4, uuid } from 'zeroreg/patterns'Available: email, url, phone, date, time, ipv4, ipv6, hexColor, hex, uuid, slug, hashtag, mention, creditCard, ssn, zipCode, username, strongPassword, semver, macAddress
MIT
