Skip to content

Instantly share code, notes, and snippets.

@lanebpemberton
lanebpemberton / URL-Regex-Description.md
Last active June 18, 2021 00:36
Describing the structure of a regex designed to match a URL

Matching URLs With Regex

Summary

It can be important to match a string as a URL in form or database validation. For example, a job finding platform that asks the user to enter their portfolio website could validate the user's input to make sure their input isn't gibberish. The following regex will tell the user if a string is a valid URL that will be recognized by most popular browsers: /^(https?://)?([\da-z.-]+).([a-z.]{2,6})(:\d{1,5})?([/\w .-])/?$/

Table of Contents