1 | # ansi-regex [![Build Status](https://travis-ci.org/sindresorhus/ansi-regex.svg?branch=master)](https://travis-ci.org/sindresorhus/ansi-regex)
|
2 |
|
3 | > Regular expression for matching [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code)
|
4 |
|
5 |
|
6 | ## Install
|
7 |
|
8 | ```sh
|
9 | $ npm install --save ansi-regex
|
10 | ```
|
11 |
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ```js
|
16 | var ansiRegex = require('ansi-regex');
|
17 |
|
18 | ansiRegex().test('\u001b[4mcake\u001b[0m');
|
19 | //=> true
|
20 |
|
21 | ansiRegex().test('cake');
|
22 | //=> false
|
23 |
|
24 | '\u001b[4mcake\u001b[0m'.match(ansiRegex());
|
25 | //=> ['\u001b[4m', '\u001b[0m']
|
26 | ```
|
27 |
|
28 | *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()`.*
|
29 |
|
30 |
|
31 | ## License
|
32 |
|
33 | MIT © [Sindre Sorhus](http://sindresorhus.com)
|