Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kevva/url-regex
Regular expression for matching URLs
https://github.com/kevva/url-regex
http nodejs regex url
Last synced: 3 days ago
JSON representation
Regular expression for matching URLs
- Host: GitHub
- URL: https://github.com/kevva/url-regex
- Owner: kevva
- License: mit
- Created: 2014-09-05T17:16:00.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-08-25T10:41:15.000Z (over 4 years ago)
- Last Synced: 2024-12-31T14:14:34.768Z (14 days ago)
- Topics: http, nodejs, regex, url
- Language: JavaScript
- Size: 43 KB
- Stars: 353
- Watchers: 6
- Forks: 65
- Open Issues: 21
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# url-regex [![Build Status](http://img.shields.io/travis/kevva/url-regex.svg?style=flat)](https://travis-ci.org/kevva/url-regex)
> Regular expression for matching URLs
Based on this [gist](https://gist.github.com/dperini/729294) by Diego Perini.
## Install
```
$ npm install url-regex
```## Usage
```js
const urlRegex = require('url-regex');urlRegex().test('http://github.com foo bar');
//=> trueurlRegex().test('www.github.com foo bar');
//=> trueurlRegex({exact: true}).test('http://github.com foo bar');
//=> falseurlRegex({exact: true}).test('http://github.com');
//=> trueurlRegex({strict: false}).test('github.com foo bar');
//=> trueurlRegex({exact: true, strict: false}).test('github.com');
//=> true'foo http://github.com bar //google.com'.match(urlRegex());
//=> ['http://github.com', '//google.com']
```## API
### urlRegex([options])
Returns a `RegExp` for matching URLs.
#### options
##### exact
Type: `boolean`
Default: `false`Only match an exact string. Useful with `RegExp#test` to check if a string is a URL.
##### strict
Type: `boolean`
Default: `true`Force URLs to start with a valid protocol or `www`. If set to `false` it'll match the TLD against a list of valid [TLDs](https://github.com/stephenmathieson/node-tlds).
## Related
- [get-urls](https://github.com/sindresorhus/get-urls) - Get all URLs in text
- [linkify-urls](https://github.com/sindresorhus/linkify-urls) - Linkify URLs in text## License
MIT © [Kevin Mårtensson](https://github.com/kevva) and [Diego Perini](https://github.com/dperini)