Skip to content

Instantly share code, notes, and snippets.

View giannifontanot's full-sized avatar
🚀
To Infinity and Beyond!

Gianni Fontanot giannifontanot

🚀
To Infinity and Beyond!
View GitHub Profile
@giannifontanot
giannifontanot / regex-tutorial.md
Last active February 14, 2022 03:04
Regex For The Uninitiated- URL Example

Regex For The Uninitiated - URL Example

Regex expressions are not easy to decipher. What is that? The first time you see one, you may think, "Hey, someone's keyboard is broken, look at this alien code". Well, it happens that it is a very clever code, actually. In just one Regex line you have a complete set of instructions to evaluate whether a user's input follows a pattern or not. In this tutorial, we will clearly, concisely, and undoubtedly explain how a regular expression checks a URL pattern. :-)

Summary

The first half of this tutorial contains an explanation of all the parts that make a regex, and how they work together. The second half is a real example of a regular expression that checks how a URL string matches a regex pattern. In this tutorial we will use the following regex literal:

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