1.0.1 • Published 6 years ago

url-regex-local v1.0.1

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

url-regex-local

Regular expression for matching URLs

Based on this gist by Diego Perini.

Install

$ npm install --save url-regex-local

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({exact: true, local: true}).test('http://orgchart/index.php');
//=> 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 regex 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.

local

Type: boolean Default: false

Allow also to test URLs with private network hosts. If set to true it'll match local URLs like http://forge/library/home/ (without TLD).

Related

License

MIT © Kevin Mårtensson and Diego Perini