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.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # url-regex [![Build Status](http://img.shields.io/travis/kevva/url-regex.svg?style=flat)](https://travis-ci.org/kevva/url-regex)
  2. > Regular expression for matching URLs
  3. Based on this [gist](https://gist.github.com/dperini/729294) by Diego Perini.
  4. ## Install
  5. ```
  6. $ npm install --save url-regex
  7. ```
  8. ## Usage
  9. ```js
  10. var urlRegex = require('url-regex');
  11. urlRegex().test('http://github.com foo bar');
  12. //=> true
  13. urlRegex().test('www.github.com foo bar');
  14. //=> true
  15. urlRegex({exact: true}).test('http://github.com foo bar');
  16. //=> false
  17. urlRegex({exact: true}).test('http://github.com');
  18. //=> true
  19. 'foo http://github.com bar //google.com'.match(urlRegex());
  20. //=> ['http://github.com', '//google.com']
  21. ```
  22. ## API
  23. ### urlRegex(options)
  24. Returns a regex for matching URLs.
  25. #### options
  26. ##### exact
  27. Type: `boolean`
  28. Default: `false` *(Matches any URL in a string)*
  29. Only match an exact string.
  30. Useful with `RegExp#test` to check if a string is a URL.
  31. ## License
  32. MIT © [Kevin Mårtensson](https://github.com/kevva) and [Diego Perini](https://github.com/dperini)