Projekt

Obecné

Profil

Stáhnout (4.39 KB) Statistiky
| Větev: | Revize:
1
# regex-not [![NPM version](https://img.shields.io/npm/v/regex-not.svg?style=flat)](https://www.npmjs.com/package/regex-not) [![NPM monthly downloads](https://img.shields.io/npm/dm/regex-not.svg?style=flat)](https://npmjs.org/package/regex-not) [![NPM total downloads](https://img.shields.io/npm/dt/regex-not.svg?style=flat)](https://npmjs.org/package/regex-not) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/regex-not.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/regex-not)
2

    
3
> Create a javascript regular expression for matching everything except for the given string.
4

    
5
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
6

    
7
## Install
8

    
9
Install with [npm](https://www.npmjs.com/):
10

    
11
```sh
12
$ npm install --save regex-not
13
```
14

    
15
## Usage
16

    
17
```js
18
var not = require('regex-not');
19
```
20

    
21
The main export is a function that takes a string an options object.
22

    
23
```js
24
not(string[, options]);
25
```
26

    
27
**Example**
28

    
29
```js
30
var not = require('regex-not');
31
console.log(not('foo'));
32
//=> /^(?:(?!^(?:foo)$).)+$/
33
```
34

    
35
**Strict matching**
36

    
37
By default, the returned regex is for strictly (not) matching the exact given pattern (in other words, "match this string if it does NOT _exactly equal_ `foo`"):
38

    
39
```js
40
var re = not('foo');
41
console.log(re.test('foo'));     //=> false
42
console.log(re.test('bar'));     //=> true
43
console.log(re.test('foobar'));  //=> true
44
console.log(re.test('barfoo'));  //=> true
45
```
46

    
47
### .create
48

    
49
Returns a string to allow you to create your own regex:
50

    
51
```js
52
console.log(not.create('foo'));
53
//=> '(?:(?!^(?:foo)$).)+'
54
```
55

    
56
### Options
57

    
58
**options.contains**
59

    
60
You can relax strict matching by setting `options.contains` to true (in other words, "match this string if it does NOT _contain_ `foo`"):
61

    
62
```js
63
var re = not('foo');
64
console.log(re.test('foo', {contains: true}));     //=> false
65
console.log(re.test('bar', {contains: true}));     //=> true
66
console.log(re.test('foobar', {contains: true}));  //=> false
67
console.log(re.test('barfoo', {contains: true}));  //=> false
68
```
69

    
70
## About
71

    
72
<details>
73
<summary><strong>Contributing</strong></summary>
74

    
75
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
76

    
77
</details>
78

    
79
<details>
80
<summary><strong>Running Tests</strong></summary>
81

    
82
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:
83

    
84
```sh
85
$ npm install && npm test
86
```
87

    
88
</details>
89

    
90
<details>
91
<summary><strong>Building docs</strong></summary>
92

    
93
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
94

    
95
To generate the readme, run the following command:
96

    
97
```sh
98
$ npm install -g verbose/verb#dev verb-generate-readme && verb
99
```
100

    
101
</details>
102

    
103
### Related projects
104

    
105
You might also be interested in these projects:
106

    
107
* [regex-cache](https://www.npmjs.com/package/regex-cache): Memoize the results of a call to the RegExp constructor, avoiding repetitious runtime compilation of… [more](https://github.com/jonschlinkert/regex-cache) | [homepage](https://github.com/jonschlinkert/regex-cache "Memoize the results of a call to the RegExp constructor, avoiding repetitious runtime compilation of the same string and options, resulting in surprising performance improvements.")
108
* [to-regex](https://www.npmjs.com/package/to-regex): Generate a regex from a string or array of strings. | [homepage](https://github.com/jonschlinkert/to-regex "Generate a regex from a string or array of strings.")
109

    
110
### Contributors
111

    
112
| **Commits** | **Contributor** | 
113
| --- | --- |
114
| 9 | [jonschlinkert](https://github.com/jonschlinkert) |
115
| 1 | [doowb](https://github.com/doowb) |
116
| 1 | [EdwardBetts](https://github.com/EdwardBetts) |
117

    
118
### Author
119

    
120
**Jon Schlinkert**
121

    
122
* [linkedin/in/jonschlinkert](https://linkedin.com/in/jonschlinkert)
123
* [github/jonschlinkert](https://github.com/jonschlinkert)
124
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
125

    
126
### License
127

    
128
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
129
Released under the [MIT License](LICENSE).
130

    
131
***
132

    
133
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on February 19, 2018._
(2-2/4)