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.
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 \.-]*)*\/?$/