url-regex

Regular expression for matching URLs

MIT 21 个版本
安装
npm install url-regex
yarn add url-regex
pnpm add url-regex
bun add url-regex
README

url-regex Build Status

Regular expression for matching URLs

Based on this gist by Diego Perini.

Install

$ npm install url-regex

Usage

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

License

MIT © Kevin Mårtensson and Diego Perini

版本列表
5.0.0 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
2.0.1 2014-11-19
2.0.0 2014-11-19
1.0.4 2014-10-27
1.0.3 2014-09-05
1.0.2 2014-09-05
1.0.1 2014-09-05