2 min read

ReX.js is a helper library written in TypeScript for writing Regular Expressions. Yesterday, ReX.js v1.0.0, the first major version was released. Being written in TypeScript, it provides great autocompletion and development experience across various modern code editors. One of the main advantages of using ReX.js is its ability to document every line of code without hassles.

Anatomy of  ReX.js v1.0.0

ReX.js is structured as namespace consisting of the following modules:

  • Matcher: It is the class used to construct and use matching expressions.
  • Replacer: The Replacer class is used to construct and use replacement expressions.
  • Operation: This class represents a basic operation that is applied to expressions constructors.
  • Parser: The parser class used to parse and execute Regexps. It is used by Matcher and implements polyfills for named groups and partially for look behinds.
  • ReXer: It is used to construct Regexps. The Matcher and Replacer classes inherit from ReXer.

The GitHub page says that the Matcher and Replacer classes will be used more likely by developers. The other classes would more likely be used for extendability and advanced use cases.

Advanced use of ReX.js v1.0.0

Beyond basic Regex operations, ReX.js also provides options for extending its functionality.

Operations and channels

Every method used in ReX.js is just adding a new Operation to ReXer. An Operation can then be stringified using its own stringify method.

A concept of channels is introduced to construct linear Regexps from nested function expressions. A channel is simply an array of Operations. The channels themselves are stored as an array in ReXer.

Snippets

Snippets are available if you want to reuse any kind of Operation configuration. Snippets provide an option to assign the given config to a name for later reuse.

Methods and extensions

Methods are ways to reuse and apply custom operations while extensions are just arrays of methods.

Installing ReX.js v1.0.0

ReX.js is available on NPM as a package. You can include it in your current project by using:

npm install @areknawo/rex

If you’re using Yarn, then use the following command:

yarn add @areknawo/rex

For more details and documentation, visit the ReX.js GitHub page.

Read next

Manipulating text data using Python Regular Expressions (regex)

Introducing Howler.js, a Javascript audio library with full cross-browser support

low.js, a Node.js port for embedded systems


Subscribe to the weekly Packt Hub newsletter. We'll send you the results of our AI Now Survey, featuring data and insights from across the tech landscape.

* indicates required