Last change
on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | # ip-regex [![Build Status](https://travis-ci.org/sindresorhus/ip-regex.svg?branch=master)](https://travis-ci.org/sindresorhus/ip-regex)
|
---|
| 2 |
|
---|
| 3 | > Regular expression for matching IP addresses
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | ## Install
|
---|
| 7 |
|
---|
| 8 | ```
|
---|
| 9 | $ npm install --save ip-regex
|
---|
| 10 | ```
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | ## Usage
|
---|
| 14 |
|
---|
| 15 | ```js
|
---|
| 16 | const ipRegex = require('ip-regex');
|
---|
| 17 |
|
---|
| 18 | // Contains an IP address?
|
---|
| 19 | ipRegex().test('unicorn 192.168.0.1');
|
---|
| 20 | //=> true
|
---|
| 21 |
|
---|
| 22 | // Is an IP address?
|
---|
| 23 | ipRegex({exact: true}).test('unicorn 192.168.0.1');
|
---|
| 24 | //=> false
|
---|
| 25 |
|
---|
| 26 | ipRegex.v6({exact: true}).test('1:2:3:4:5:6:7:8');
|
---|
| 27 | //=> true
|
---|
| 28 |
|
---|
| 29 | 'unicorn 192.168.0.1 cake 1:2:3:4:5:6:7:8 rainbow'.match(ipRegex());
|
---|
| 30 | //=> ['192.168.0.1', '1:2:3:4:5:6:7:8']
|
---|
| 31 | ```
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | ## API
|
---|
| 35 |
|
---|
| 36 | ### ipRegex([options])
|
---|
| 37 |
|
---|
| 38 | Returns a regex for matching both IPv4 and IPv6.
|
---|
| 39 |
|
---|
| 40 | ### ipRegex.v4([options])
|
---|
| 41 |
|
---|
| 42 | Returns a regex for matching IPv4.
|
---|
| 43 |
|
---|
| 44 | ### ipRegex.v6([options])
|
---|
| 45 |
|
---|
| 46 | Returns a regex for matching IPv6.
|
---|
| 47 |
|
---|
| 48 | #### options.exact
|
---|
| 49 |
|
---|
| 50 | Type: `boolean`<br>
|
---|
| 51 | Default: `false` *(Matches any IP address in a string)*
|
---|
| 52 |
|
---|
| 53 | Only match an exact string. Useful with `RegExp#test()` to check if a string is an IP address.
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | ## Related
|
---|
| 57 |
|
---|
| 58 | - [is-ip](https://github.com/sindresorhus/is-ip) - Check if a string is an IP address
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | ## License
|
---|
| 62 |
|
---|
| 63 | MIT © [Sindre Sorhus](https://sindresorhus.com)
|
---|
Note:
See
TracBrowser
for help on using the repository browser.