# url-regex

> Regular expression for matching URLs

Latest version **5.0.0** (published 2019-04-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install url-regex
pnpm add url-regex
yarn add url-regex
bun add url-regex
```

## Health

**Score 13/100 (F)** — status: abandoned.

Positive: has types package; high quality score.

Warnings: low downloads; no esm support; has vulnerabilities.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2019-04-21 |
| First published | 2014-09-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/url-regex) |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 2 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 1 |
| Install scripts | no |
| GitHub stars | 354 |
| Author | Kevin Mårtensson |
| Maintainers | kevva, sindresorhus |
| Keywords | regex, string, url |

## Links

- npm: https://www.npmjs.com/package/url-regex
- Repository: https://github.com/kevva/url-regex
- Homepage: https://github.com/kevva/url-regex#readme
- Issues: https://github.com/kevva/url-regex/issues
- npm.io page: https://npm.io/package/url-regex

## Dependencies (2)

- [tlds](https://npm.io/package/tlds.md) ^1.203.0
- [ip-regex](https://npm.io/package/ip-regex.md) ^4.1.0

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 5.0.0 (latest) — 2019-04-21
- 4.1.1 — 2017-06-13
- 4.1.0 — 2017-06-02
- 4.0.0 — 2016-09-29
- 3.2.0 — 2016-06-08
- 3.1.1 — 2016-04-13
- 3.1.0 — 2015-12-05
- 3.0.1 — 2015-12-05
- 3.0.0 — 2015-06-22
- 2.1.3 — 2015-06-16
- 2.1.2 — 2014-12-01
- 2.1.1 — 2014-11-26
- 2.1.0 — 2014-11-26
- 2.0.3 — 2014-11-21
- 2.0.2 — 2014-11-19
- … 6 more at https://npm.io/package/url-regex/versions

## 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');
//=> true

urlRegex().test('www.github.com foo bar');
//=> true

urlRegex({exact: true}).test('http://github.com foo bar');
//=> false

urlRegex({exact: true}).test('http://github.com');
//=> true

urlRegex({strict: false}).test('github.com foo bar');
//=> true

urlRegex({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`<br>
Default: `false`

Only match an exact string. Useful with `RegExp#test` to check if a string is a URL.

##### strict

Type: `boolean`<br>
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)

---
_Source: https://npm.io/package/url-regex · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
