You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # ip-regex [![Build Status](https://travis-ci.org/sindresorhus/ip-regex.svg?branch=master)](https://travis-ci.org/sindresorhus/ip-regex)
  2. > Regular expression for matching IP addresses
  3. ## Install
  4. ```sh
  5. $ npm install --save ip-regex
  6. ```
  7. ## Usage
  8. ```js
  9. var ipRegex = require('ip-regex');
  10. // contains an IP address
  11. ipRegex().test('unicorn 192.168.0.1');
  12. //=> true
  13. // is an IP address
  14. ipRegex({exact: true}).test('unicorn 192.168.0.1');
  15. //=> false
  16. ipRegex.v6({exact: true}).test('1:2:3:4:5:6:7:8');
  17. //=> true
  18. 'unicorn 192.168.0.1 cake 1:2:3:4:5:6:7:8 rainbow'.match(ipRegex());
  19. //=> ['192.168.0.1', '1:2:3:4:5:6:7:8']
  20. ```
  21. ## API
  22. ### ipRegex(options)
  23. Returns a regex for matching both IPv4 and IPv6.
  24. ### ipRegex.v4(options)
  25. Returns a regex for matching IPv4.
  26. ### ipRegex.v6(options)
  27. Returns a regex for matching IPv6.
  28. #### options.exact
  29. Type: `boolean`
  30. Default: `false` *(Matches any IP address in a string)*
  31. Only match an exact string.
  32. Useful with `RegExp#test` to check if a string is an IP address.
  33. ## License
  34. MIT © [Sindre Sorhus](http://sindresorhus.com)