☕ Relax and write some Regex
Creates regular expressions that are composable, reusable, and commentable.
npm install reglax
const {
matchers,
flags,
whole,
repeat,
alpha,
numeric,
and,
or,
wildcard,
extra,
capture,
group,
look,
regex
} = require('reglax')
// or
import { something } from 'reglax'
See generated typedoc.
test/index.spec.js can be a good reference.
regex(
whole(
or(numeric(7), capture(alpha(0, 3)), extra(matchers.ANY, matchers.LAZY))
),
and(flags.GLOBAL, flags.INSENSITIVE)
)
// -> /^\d{7}|([A-z]{0,3})|.+?$/gi
// Matches all New York Driver's licenses
regex(
or(
and(alpha(1), numeric(7)),
and(alpha(1), numeric(18)),
and(numeric(8, 9)),
and(numeric(16)),
and(alpha(8))
)
)
// -> /[A-z]{1}\d{7}|[A-z]{1}\d{18}|\d{8,9}|\d{16}|[A-z]{8}/