happy-url-regex
A regular expression for matching URLs.
A fork of url-regex by Kevin Mårtensson, which is based on a gist by Diego Perini.
Why fork?
Because of a niche, client-side use case.
Webpack uglification would complain when using the original url-regex
package as it contains ES6 arrow functions and template strings. I have opted to fork the repository and use babel rather than transpiling url-regex
during webpack build.
Install
$ npm install --save happy-url-regex
or
$ yarn add happy-url-regex
Usage
// true // true // false // true // true // true 'foo http://github.com bar //google.com'// ['http://github.com', '//google.com']
API
happyUrlRegex(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.
Related
- get-urls - Get all URLs in text
- linkify-urls - Linkify URLs in text
License
MIT © Kevin Mårtensson and Diego Perini