Add Site Url Validation Regex

Source URL:

Language: javascript

Created on: 2020-10-14 15:49:49

const regex = /^((ftp|http|https):\/\/)?(www.)?(?!.*(ftp|http|https|www.))[a-zA-Z0-9_-]+(\.[a-zA-Z]+)+((\/)[\w#]+)*(\/\w+\?[a-zA-Z0-9_]+=\w+(&[a-zA-Z0-9_]+=\w+)*)?$/gm;
const str = `

let m;

while ((m = regex.exec(str)) !== null) {

    if (m.index === regex.lastIndex) {
    console.log("matched :"+m[0]);
I know this is so common question & there are so many answers for this, but my problem is different, I want to accept the URL with all below formats: