^(http|https):\/\/(www\.)?[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})+(\/\S*)?$
Copy
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.
const urlRegex = /^(http|https):\/\/(www\.)?[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})+(\/\S*)?$/;
Copy