readable-regexp

CI Coverage Status TypeScript npm npm bundle size Dependency Count

Regular Expressions - quick and concise, readable and composable.

Quick example of readable-regexp

Features

๐Ÿ“– Readable

Be explicit and extract common pieces

Click to see examples

Compare a readable-regexp expression:

With normal JS RegExp:

In a more complex use case, we can destructure the expression into manageable small parts:

This is far more readable and debuggable than the equivalent RegExp:

๐Ÿ“ Flexible and Concise

Multiple shorthands and syntax options

Click to see examples

Without all the shorthands, an expression looks like this:

Whenever a function takes a single string literal, you can use a tagged template literal to remove the brackets:

When there is only one token in a quantifier or group, you can chain it with . instead of using a bracket:

There are shorthands for negating a character class or a lookaround:

As you can see, most of the distracting brackets are gone, and you are left with a clean and concise expression.

๐Ÿ›Ÿ Safe

Type check, auto-complete, and runtime safeguards

Click to see examples

Some errors can be avoided just by writing in readable-regexp:

Some errors can be caught by TypeScript at compile time:

Some can be caught at run time:

Last updated