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 .-])/?$/