Debian Codegraph @

.verb.md

raw symbols SCIP
1 ## Usage
2
3 ```js
4 var not = require('regex-not');
5 ```
6
7 The main export is a function that takes a string an options object.
8
9 ```js
10 not(string[, options]);
11 ```
12
13 **Example**
14
15 ```js
16 var not = require('regex-not');
17 console.log(not('foo'));
18 //=> /^(?:(?!^(?:foo)$).)+$/
19 ```
20
21 **Strict matching**
22
23 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`"):
24
25 ```js
26 var re = not('foo');
27 console.log(re.test('foo')); //=> false
28 console.log(re.test('bar')); //=> true
29 console.log(re.test('foobar')); //=> true
30 console.log(re.test('barfoo')); //=> true
31 ```
32
33 ### .create
34
35 Returns a string to allow you to create your own regex:
36
37 ```js
38 console.log(not.create('foo'));
39 //=> '(?:(?!^(?:foo)$).)+'
40 ```
41
42 ### Options
43
44 **options.contains**
45
46 You can relax strict matching by setting `options.contains` to true (in other words, "match this string if it does NOT _contain_ `foo`"):
47
48 ```js
49 var re = not('foo');
50 console.log(re.test('foo', {contains: true})); //=> false
51 console.log(re.test('bar', {contains: true})); //=> true
52 console.log(re.test('foobar', {contains: true})); //=> false
53 console.log(re.test('barfoo', {contains: true})); //=> false
54 ```