readable-regexp

CIarrow-up-right Coverage Statusarrow-up-right TypeScriptarrow-up-right npmarrow-up-right npm bundle sizearrow-up-right Dependenciesarrow-up-right

Regular Expressions - quick and concise, readable and composable.

Quick example of readable-regexp

Features

๐Ÿ“– Readable

Be explicit and extract common pieces

chevron-rightClick to see exampleshashtag

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

chevron-rightClick to see exampleshashtag

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

chevron-rightClick to see exampleshashtag

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