EasyRegex Logo
EasyRegex
New

Match Entire URLs with HTTP or HTTPS in JavaScript

javascript

Regular Expression

^(http|https):\/\/(www\.)?[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})+(\/\S*)?$
Copy
Do you have Feedback?

Explanation

This regex pattern matches entire URLs starting with either 'http' or 'https', followed by '://'. It then optionally matches 'www.' before the domain name which consists of alphanumeric characters and hyphens. The domain name must have at least one '.' and end with at least 2 characters. It also allows an optional path after the domain name.

javascript

Example Usage

const urlRegex = /^(http|https):\/\/(www\.)?[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})+(\/\S*)?$/;
Copy
Test the expression

Similar Regular Expressions