“Regex URL válido” Respostas de código

Adicionar regex de validação de URL do site

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 = `http://www.sample.com
https://www.sample.com
http://www.sample.com/xyz
www.sample.com
www.sample.com/xyz/#/xyz
sample.com
www.sample.com
mofiz.com
kolim.com
www.murikhao.www.sample.com
http://murihao.www.sample.com
http://www.sample.com/xyz?abc=dkd&p=q&c=2
www.sample.gov.bd
www.sample.com.en
www.sample.vu


`;
let m;

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

    if (m.index === regex.lastIndex) {
        regex.lastIndex++;
    }
    console.log("matched :"+m[0]);
}
Determined Donkey

Regex URL

(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})
Important Ibex

url regex

^http[s]?:\/\/(www\.)?(.*)?\/?(.)*
Uptight Unicorn

padrão regex que verifica o URL

https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)
Mystic Dev

URLs regex

// It will include the space before as well (if it has one)

/(^| )(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,8}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi
florinrelea

Regex URL válido

/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?: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})(?:[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]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/i
Sleepy Squirrel

Respostas semelhantes a “Regex URL válido”

Perguntas semelhantes a “Regex URL válido”

Mais respostas relacionadas para “Regex URL válido” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código