readable-regexp
TypeDocGitHubnpm
  • readable-regexp
  • Getting Started
    • Installation
    • Usage
  • API Reference
    • Character Classes
    • Anchors
    • Special Tokens
    • Quantifiers
    • Groups
    • Extras
    • TypeDoc
  • Custom Extensions
    • Custom Tokens
      • Step 1: Type Definition
      • Step 2: Implementation
      • Step 3: Usage
Powered by GitBook
On this page
  1. Custom Extensions
  2. Custom Tokens

Step 3: Usage

Treat custom tokens like a built-in token

Custom tokens are integrated as part of readable-regexp. So you can use them just like how you use a built-in token.

  • Start an expression with a custom token returned by defineToken

const expr1 = notExactly`foo`.exactly`bar`.toRegExp();
// /(?!foo)[^]{3}bar/
  • Use custom tokens as part of an expression chain

const expr2 = capture.severity.matchAll.toRegExp();
// /^(error|warning|info|debug)$/e
  • Use custom tokens from the r shorthand

const expr3 = r.alpha(false).toRegExp();
// /[a-z]/
PreviousStep 2: Implementation

Last updated 1 year ago