Skip to content

Instantly share code, notes, and snippets.

@ix4
Forked from benbalter/regex.rb
Created February 18, 2020 17:58
Show Gist options
  • Save ix4/65967327ba0c836d0cc3731a5113dc87 to your computer and use it in GitHub Desktop.
Save ix4/65967327ba0c836d0cc3731a5113dc87 to your computer and use it in GitHub Desktop.
Regular expression to find government domains for websites / email addresses
# regex to match government emails. Should detect:
# foo.gov, foo.mil
# foo.gov.uk, foo.mil.uk
# foo.fed.us
# foo.govt.nz, foo.gc.ca, foo.guv.ro, gub.uy
# note: foo.gouvt, foo.gc, foo.fed.uk, etc. will technically pass, but they are invalid domains
regex = /(\.g[ou]{1,2}(v|b|vt)|\.mil|\.gc|\.fed)(\.[a-z]{2})?$/i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment