Socket
Socket
Sign inDemoInstall

ansi-regex

Package Overview
Dependencies
0
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ansi-regex

Regular expression for matching ANSI escape codes


Version published
Weekly downloads
124M
decreased by-18.33%
Maintainers
2
Install size
4.10 kB
Created
Weekly downloads
 

Package description

What is ansi-regex?

The ansi-regex npm package is used to create regular expressions to match ANSI escape codes, which are used to format output in terminal with colors, background colors, styles like bold or underline, and other text effects.

What are ansi-regex's main functionalities?

Matching ANSI escape codes

This code sample demonstrates how to use ansi-regex to match ANSI escape codes in a string. The string contains the ANSI escape codes for underlining text, followed by the word 'cake', and then the reset code to stop the underlining. The ansiRegex function is called to generate a regular expression that matches these codes.

"\u001B[4mcake\u001B[0m".match(ansiRegex());

Other packages similar to ansi-regex

Readme

Source

ansi-regex Build Status

Regular expression for matching ANSI escape codes

Install

$ npm install --save ansi-regex

Usage

var ansiRegex = require('ansi-regex');

ansiRegex().test('\u001b[4mcake\u001b[0m');
//=> true

ansiRegex().test('cake');
//=> false

'\u001b[4mcake\u001b[0m'.match(ansiRegex());
//=> ['\u001b[4m', '\u001b[0m']

It's a function so you can create multiple instances. Regexes with the global flag will have the .lastIndex property changed for each call to methods on the instance. Therefore reusing the instance with multiple calls will not work as expected for .test().

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 22 Feb 2015

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc