Skip to content
/ reglax Public

☕ Relax and write some Regex

License

Notifications You must be signed in to change notification settings

exuanbo/reglax

Repository files navigation

reglax

☕ Relax and write some Regex

npm Travis CI David License

Creates regular expressions that are composable, reusable, and commentable.

Usage

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'

API

See generated typedoc.

Examples

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}/

License

MIT

Donate

Buy Me A Coffee