Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
LICENSE | D | 12-May-2024 | 1.3 KiB | 23 | 19 | |
README.md | D | 12-May-2024 | 1.8 KiB | 65 | 39 | |
index.js | D | 12-May-2024 | 497 | 14 | 9 | |
package.json | D | 12-May-2024 | 1.8 KiB | 79 | 78 |
README.md
1# cidr-regex 2[![](https://img.shields.io/npm/v/cidr-regex.svg?style=flat)](https://www.npmjs.org/package/cidr-regex) [![](https://img.shields.io/npm/dm/cidr-regex.svg)](https://www.npmjs.org/package/cidr-regex) [![](https://api.travis-ci.org/silverwind/cidr-regex.svg?style=flat)](https://travis-ci.org/silverwind/cidr-regex) 3 4> Regular expression for matching IP addresses in CIDR notation 5 6## Install 7 8```sh 9$ npm install --save cidr-regex 10``` 11 12## Usage 13 14```js 15const cidrRegex = require('cidr-regex'); 16 17// Contains a CIDR IP address? 18cidrRegex().test('foo 192.168.0.1/24'); 19//=> true 20 21// Is a CIDR IP address? 22cidrRegex({exact: true}).test('foo 192.168.0.1/24'); 23//=> false 24 25cidrRegex.v6({exact: true}).test('1:2:3:4:5:6:7:8/64'); 26//=> true 27 28'foo 192.168.0.1/24 bar 1:2:3:4:5:6:7:8/64 baz'.match(cidrRegex()); 29//=> ['192.168.0.1/24', '1:2:3:4:5:6:7:8/64'] 30``` 31 32## API 33 34### cidrRegex([options]) 35 36Returns a regex for matching both IPv4 and IPv6 CIDR IP addresses. 37 38### cidrRegex.v4([options]) 39 40Returns a regex for matching IPv4 CIDR IP addresses. 41 42### cidrRegex.v6([options]) 43 44Returns a regex for matching IPv6 CIDR IP addresses. 45 46#### options.exact 47 48Type: `boolean`<br> 49Default: `false` *(Matches any CIDR IP address in a string)* 50 51Only match an exact string. Useful with `RegExp#test()` to check if a string is a CIDR IP address. 52 53 54## Related 55 56- [is-cidr](https://github.com/silverwind/is-cidr) - Check if a string is an IP address in CIDR notation 57- [is-ip](https://github.com/sindresorhus/is-ip) - Check if a string is an IP address 58- [ip-regex](https://github.com/sindresorhus/ip-regex) - Regular expression for matching IP addresses 59 60## License 61 62© [silverwind](https://github.com/silverwind), distributed under BSD licence 63 64Based on previous work by [Felipe Apostol](https://github.com/flipjs) 65