src/isValidUri.js
function urlStyleUriRegex() {
  const protocol = '(?:[A-Za-z]{3,9}://)';
  const auth = '(?:\\S+(?::\\S*)?@)?';
  const ipv4 = '(?:\\[?([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\]?';
  const host = '(?:(?:[a-zA-Z0-9]-*)*[a-zA-Z0-9]+)';
  const domain = '(?:\\.(?:[a-zA-Z0-9]-*)*[a-zA-Z0-9]+)*';
  const tld = '(?:\\.(?:[a-zA-Z]{2,}))\\.?';
  const port = '(?::\\d{2,5})?';
  const path = '(?:[/?#][\\x21-\\x7F]*)?'; // ascii no whitespaces
  const regex = `(?:${protocol}|www\\.)${auth}(?:localhost|${ipv4}|${host}${domain}${tld})${port}${path}`;

  return new RegExp(`^${regex}$`, 'i');
}
function urlStyleUriRegex() {
  const protocol = '(?:[A-Za-z]{3,9}://)';
  const auth = '(?:\\S+(?::\\S*)?@)?';
  const ipv4 = '(?:\\[?([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\]?';
  const host = '(?:(?:[a-zA-Z0-9]-*)*[a-zA-Z0-9]+)';
  const domain = '(?:\\.(?:[a-zA-Z0-9]-*)*[a-zA-Z0-9]+)*';
  const tld = '(?:\\.(?:[a-zA-Z]{2,}))\\.?';
  const port = '(?::\\d{2,5})?';
  const path = '(?:[/?#][\\x21-\\x7F]*)?'; // ascii no whitespaces
  const regex = `(?:${protocol}|www\\.)${auth}(?:localhost|${ipv4}|${host}${domain}${tld})${port}${path}`;

  return new RegExp(`^${regex}$`, 'i');
}
function urlStyleUriRegex ( ) { const protocol = '(?:[A-Za-z]{3,9}://)' ; const auth = '(?:\\S+(?::\\S*)?@)?' ; const ipv4 = '(?:\\[?([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\]?' ; const host = '(?:(?:[a-zA-Z0-9]-*)*[a-zA-Z0-9]+)' ; const domain = '(?:\\.(?:[a-zA-Z0-9]-*)*[a-zA-Z0-9]+)*' ; const tld = '(?:\\.(?:[a-zA-Z]{2,}))\\.?' ; const port = '(?::\\d{2,5})?' ; const path = '(?:[/?#][\\x21-\\x7F]*)?' ; // ascii no whitespaces const regex = ` ${ protocol } \\ ${ auth } ${ ipv4 } ${ host } ${ domain } ${ tld } ${ port } ${ path } ` ; return new RegExp ( ` ${ regex } ` , 'i' ) ; }
Compose a url style uri regex

The most common form of URI is the Uniform Resource Locator (URL),
frequently referred to informally as a web address. More rarely seen in usage
is the Uniform Resource Name (URN), which was designed to complement URLs by
providing a mechanism for the identification of resources in particular
namespaces.
- scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment]
- https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
Compose a url style uri regex