Skip to content

Instantly share code, notes, and snippets.

@benbalter
Last active March 5, 2023 03:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benbalter/6147066 to your computer and use it in GitHub Desktop.
Save benbalter/6147066 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