Skip to content

Instantly share code, notes, and snippets.

@savitamanchanda
savitamanchanda / URL_tutorial_regex.md
Created March 20, 2023 23:55
Computer Science for JavaScript Challenge: Regex URL Tutorial

Computer Science for JavaScript Challenge: Regex URL Tutorial

This tutorial will show how regular expression (regex) is used to match URL addresses. This example will help build a basic understanding of regular expressions. By the end of this tutorial, you will be able to understand what each component represents, how they can be implemented in code and how to validate the strings to match a specific criteria.

Summary

The following regex is designed to match a URL string, including optional protocols (http/https) and paths.

/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/