🚀 Launch Week Day 3:Introducing Supply Chain Attack Campaigns Tracking.Learn More →
Socket
Book a DemoInstallSign in
Socket

pretty-regex

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pretty-regex

Print regular expressions with syntax highlighting in the terminal. Useful for debugging, visually inspecting and understanding complex regex patterns.

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

pretty-regex NPM version NPM monthly downloads NPM total downloads

Print regular expressions with syntax highlighting in the terminal. Useful for debugging, visually inspecting and understanding complex regex patterns.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.

Install

Install with npm:

$ npm install --save pretty-regex

Usage

import { parse } from 'pretty-regex';

// Parse a regex pattern into a tree
const tree = parse(/foo(bar)+[a-z]/);

// Get the parsed AST
console.log(tree);

// Get colorized output
console.log(tree.print());

API

parse(regex)

Parse a regular expression pattern into a tree structure that can be used to create colorized output.

Params

  • regex {RegExp|String}: The regex pattern to parse.

Returns

  • {Object}: Returns a tree with nodes for each part of the regex.

Example

import { parse } from 'pretty-regex';

// Parse a string pattern
const tree = parse('foo[a-z]');

// Or pass a RegExp instance
const tree = parse(/foo[a-z]/);

// Customize colors with your own print function
// or use the built-in tree.print() method
console.log(tree.print());

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Author

Jon Schlinkert

License

Copyright © 2025, Jon Schlinkert. Released under the MIT License.

This file was generated by verb-generate-readme, v0.8.0, on April 18, 2025.

FAQs

Package last updated on 19 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts