Skip to content

Instantly share code, notes, and snippets.

Avatar
🧐

Robyn Graham robyng

🧐
View GitHub Profile
@robyng
robyng / url-regex-explained-with-examples.md
Last active Jan 24, 2022
This URL regex matches URLs that have https or not, subdomains or not, top-level domains, extensions, and paths
View url-regex-explained-with-examples.md

URL Regex Explained With Examples

This gist shows how a regular expression (regex) is used to match URLs. Each part of the regex is explained within the context of the URL with examples.

Summary

The regular expression below matches URLs. It matches URLs with or without the internet protocol.

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