Regex to Match SHA-256 Hash Strings

Validate SHA-256 hash strings consisting of exactly 64 hexadecimal characters. Matches the standard output format of SHA-256 hashing algorithms. Free regex tester.

Regular Expression

/^[a-fA-F0-9]{64}$/

Token Breakdown

TokenDescription
^Anchors at the start of the string (or line in multiline mode)
[a-fA-F0-9]Character class — matches any one of: a-fA-F0-9
{64}Matches exactly 64 times
$Anchors at the end of the string (or line in multiline mode)

Detailed Explanation

This regex validates SHA-256 hash strings, which are the output of the SHA-256 cryptographic hash function. Here is the token-by-token breakdown:

^ — Anchors the match at the start of the string, ensuring the hash starts at the beginning with no leading characters.

[a-fA-F0-9]{64} — A character class matching exactly 64 hexadecimal characters. The class includes lowercase hex letters (a-f), uppercase hex letters (A-F), and digits (0-9). SHA-256 produces a 256-bit hash value, which when represented in hexadecimal uses exactly 64 characters (each hex character represents 4 bits: 256 / 4 = 64).

$ — Anchors the match at the end of the string, ensuring exactly 64 characters with nothing trailing.

No flags are used since this validates a single hash string and case is handled by the character class.

SHA-256 is one of the most widely used cryptographic hash functions, part of the SHA-2 family designed by the NSA. It is used in TLS/SSL certificates, blockchain technology (Bitcoin mining), digital signatures, password hashing (as part of more complex schemes), file integrity verification, and Git commit hashes (which use SHA-1 but are migrating to SHA-256).

Examples of SHA-256 hashes include: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 (the hash of an empty string). This pattern is useful for input validation, hash verification tools, and security applications that need to confirm a string is a valid SHA-256 hash.

Example Test Strings

InputExpected
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855Match
a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2Match
too-shortNo Match
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzNo Match
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855aaNo Match

Try It — Interactive Tester

//
gimsuy
No matches found.
Pattern: 17 charsFlags: noneMatches: 0

Ctrl+Shift+C to copy regex

Customize this pattern →