Skip to content

Instantly share code, notes, and snippets.

@derekmeduri
derekmeduri / RegexTutorial.MD
Last active August 31, 2023 00:14
Matching a URL with Regex Tutorial

Matching a URL with Regular Expression Tutorial

This guide was created to help myself and you learn more about regular expressions and how to use them. Regular expressions are special characters that define a search pattern.

Summary

The regular expression, or regex for short, below is a search pattern for matching a Url. Since this regular expression is between two slashes it is called a regular expression literal. It is made up of anchors, grouping constructions, bracket expressions, and quantifiers. We will look at each component of the regular expression so they make more sense.
/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/