Skip to content

Instantly share code, notes, and snippets.

@brydavis
Last active January 11, 2024 08:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brydavis/0c7da92bd508195744708eeb2b54ac96 to your computer and use it in GitHub Desktop.
Save brydavis/0c7da92bd508195744708eeb2b54ac96 to your computer and use it in GitHub Desktop.
Regex for URLs in Go

Regexs

Quick reference for regexs in Golang that match common string patterns out there in the wild.

URLs

^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/|\/|\/\/)?[A-z0-9_-]*?[:]?[A-z0-9_-]*?[@]?[A-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$

Emails

^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$

^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,4}$

Other References

https://github.com/lucasjones/reggen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment