Skip to content

Instantly share code, notes, and snippets.

@grudgecat
grudgecat / regex_url.md
Last active August 28, 2021 01:33
RegEx Tutorial using URL pattern matching

RegEx Tutorial on matching a URL

This is a tutorial with the purpose of introducing some basic concepts of regular expressions, or more commonly known as RegEx in which a pattern string of characters is used to define a specific search pattern to locate and/or validate character sequences in a string. I will break down the RegEx used to validate a URL in order to demonstrate how they can be built and used.

Summary

This tutorial will provide basic regular expression information and then use a given expression to validate a URL to elucidate RegEx pattern matching concepts and syntax.

Sample RegEx for matching and validating a URL:
/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/