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
| Token | Description |
|---|---|
| ^ | 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
| Input | Expected |
|---|---|
| e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 | Match |
| a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2 | Match |
| too-short | No Match |
| zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz | No Match |
| e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855aa | No Match |
Try It — Interactive Tester
17 charsFlags: noneMatches: 0Ctrl+Shift+C to copy regex
Related Regex Patterns
Regex to Match MD5 Hash Strings
/^[a-fA-F0-9]{32}$/
Regex to Match Hexadecimal Numbers
/^(?:0x)?[0-9a-fA-F]+$/i
Regex to Match Base64 Encoded Strings
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/m
Regex to Match API Key Formats
/(?:sk|pk|api|key)[-_]?(?:live|test|prod|dev)?[-_]?[A-Za-z0-9]{16,64}/g