/**
 * Rule borrowed from https://forums.devshed.com/javascript-development/493764-regexp-match-url-pattern-post1944160.html#post1944160
 *
 * @author Kravvitz (https://forums.devshed.com/author/kravvitz)
 * @type {RegExp}
 */
const validUrlPattern = new RegExp('^(https?:\\/\\/)?' // protocol
  + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' // domain name
  + '((\\d{1,3}\.){3}\\d{1,3}))' // OR ip (v4) address
  + '(\\:\\d+)?(\/[-a-z\\d%_.~+]*)*' // port and path
  + '(\\?[;&a-z\\d%_.~+=-]*)?' // query string
  + '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator

export const compulsoryProtocolValidUrlPattern = new RegExp('^(https?:\\/\\/)' // compulsory protocol
  + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' // domain name
  + '((\\d{1,3}\.){3}\\d{1,3}))' // OR ip (v4) address
  + '(\\:\\d+)?(\/[-a-z\\d%_.~+]*)*' // port and path
  + '(\\?[;&a-z\\d%_.~+=-]*)?' // query string
  + '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator

export const protocolLessValidUrlPattern = new RegExp(
  '^'
  // user:pass authentication
  + '(?:\\S+(?::\\S*)?@)?'
  + '(?:'
  // IP address exclusion
  // private & local networks
  + '(?!(?:10|127)(?:\\.\\d{1,3}){3})'
  + '(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})'
  + '(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})'
  // IP address dotted notation octets
  // excludes loopback network 0.0.0.0
  // excludes reserved space >= 224.0.0.0
  // excludes network & broacast addresses
  // (first & last IP address of each class)
  + '(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])'
  + '(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}'
  + '(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))'
  + '|'
  // host name
  + '(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)'
  // domain name
  + '(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*'
  // TLD identifier
  + '(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))'
  // TLD may end with dot
  + '\\.?'
  + ')'
  // port number
  + '(?::\\d{2,5})?'
  // resource path
  + '(?:[/?#]\\S*)?'
  + '$', 'i'
);

export const validTwitterProfileUrlPattern = new RegExp(
  '^(https?:\\/\\/)' // compulsory protocol
  + 'twitter\\.com\\/([a-zA-Z0-9_]+)$'
);

export const validFacebookProfileUrlPattern = new RegExp(
  '^(https?:\\/\\/)' // compulsory protocol
  + 'facebook\\.com\\/([a-zA-Z0-9_]+)$'
);

export const validGithubProfileUrlPattern = new RegExp(
  '^(https?:\\/\\/)' // compulsory protocol
  + 'github\\.com\\/([a-zA-Z0-9_]+)$'
);

export const validLinkedinProfileUrlPattern = new RegExp(
  '^(https?:\\/\\/)' // compulsory protocol
  + 'linkedin\\.com\\/([a-zA-Z0-9_]+)$'
);


export const isValidUrl = str => {
  return validUrlPattern.test(str);
};

@@ -2116,16 +2116,26 @@
 ol%0A  + '
+?(?:www.)?
 twitter%5C
@@ -2152,32 +2152,32 @@
 a-zA-Z0-9_%5D+)$'%0A
-
 );%0A%0Aexport const
@@ -2271,16 +2271,26 @@
 ol%0A  + '
+?(?:www.)?
 facebook
@@ -2425,16 +2425,26 @@
 ol%0A  + '
+?(?:www.)?
 github%5C%5C
@@ -2579,16 +2579,27 @@
 ol%0A  + '
+?(?:www.)?(
 linkedin
@@ -2607,38 +2607,81 @@
 %5C.com%5C%5C/
-(%5Ba-zA-Z0-9_%5D+
+)(((%5B%5C%5Cw%5D%7B2,3%7D)?)%7C(%5B%5E%5C%5C/%5D+%5C%5C/((%5B%5C%5Cw%7C%5C%5Cd-&#?=%5D)+%5C%5C/?)%7B1,%7D)
 )$'%0A);%0A%0A
 %0Aexport 
@@ -2672,17 +2672,16 @@
 )$'%0A);%0A%0A
-%0A
 export c

Enhance social media link regex expressions (#1869)