Skip to content

Instantly share code, notes, and snippets.

View Ms-Marlena's full-sized avatar

Marlena Hooker Moore Ms-Marlena

View GitHub Profile
@Ms-Marlena
Ms-Marlena / url-regex-tutorial.md
Last active July 31, 2023 15:22
REGEX Tutorial: URL

URL Regex Tutorial

A regex (short for "regular expression") is a pattern written in a specific way to assist with searching for text that follows a certain pattern or format. You can search for things like phone numbers, email addresses, HTML tags, URL addresses, or anything that must be written in a specific format. Regexes transcend programming languages, and do not need to be modified in order to be used from language to language. In addition to searches, regexes provide a way to verify whether user entries on a web page are formatted correctly, or contain the correct composition of characters.

Summary

This Regex regular expression can be used to match a URL within a document. I will describe the parts of the regex, as seen below in the table of contents. Hopefully, this will explain the regex and help you understand the different parts of a regex expression!

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