EasyRegex Logo
EasyRegex
Nouveau

Match Valid URL in Javascript

Javascript

Expression Régulière

/^(http(s)?:\/\/)?(www\.)?[a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/
Copier
Avez-vous des Retours ?

Explication

This regex pattern matches a valid URL. It allows for optional 'http://' or 'https://', an optional 'www.', followed by the domain name and top-level domain. It also allows for query parameters and special characters.

Javascript

Exemple d'Utilisation

const regex = /^(http(s)?:\/\/)?(www\.)?[a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/;
const url = 'https://www.example.com/page?query=123';
if (regex.test(url)) {
    console.log('Valid URL');
}
Copier
Testez l'expression

Expressions Régulières Similaires