Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active January 3, 2024 14:30
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magnetikonline/073afe7909ffdd6f10ef06a00bc3bc88 to your computer and use it in GitHub Desktop.
Save magnetikonline/073afe7909ffdd6f10ef06a00bc3bc88 to your computer and use it in GitHub Desktop.
GitHub token validation regular expressions.

GitHub token validation regular expressions

Regular expressions to check if a given GitHub token could be valid.

Personal access tokens (classic)

Classic personal access tokens are 40 characters in length, with a prefix of ghp_:

^ghp_[a-zA-Z0-9]{36}$

Fine-grained personal access tokens

Fine-grained personal access tokens (currently in beta) are 93 characters in length, with a prefix of github_pat_:

^github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59}$

GitHub Actions

Temporal tokens generated by GitHub Actions are 40 characters in length, with a prefix of ghs_:

^ghs_[a-zA-Z0-9]{36}$

Combined together

^(gh[ps]_[a-zA-Z0-9]{36}|github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59})$

Related

@acevif
Copy link

acevif commented May 25, 2023

@magnetikonline Thank you very much!

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