Regex to Match MD5 Hash Strings
Validate MD5 hash strings consisting of exactly 32 hexadecimal characters. Matches the standard output format of the MD5 message-digest algorithm. Free regex tester.
Regular Expression
/^[a-fA-F0-9]{32}$/
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 |
| {32} | Matches exactly 32 times |
| $ | Anchors at the end of the string (or line in multiline mode) |
Detailed Explanation
This regex validates MD5 hash strings, which are the output of the MD5 message-digest algorithm. Here is the token-by-token breakdown:
^ — Anchors the match at the start of the string, ensuring validation begins from the first character.
[a-fA-F0-9]{32} — A character class matching exactly 32 hexadecimal characters. The class includes lowercase hex letters (a-f), uppercase hex letters (A-F), and digits (0-9). MD5 produces a 128-bit hash value, which when represented in hexadecimal uses exactly 32 characters (each hex character represents 4 bits: 128 / 4 = 32).
$ — Anchors the match at the end of the string, ensuring exactly 32 characters with no trailing content.
No flags are used since this validates a single hash string and case sensitivity is handled by the character class including both uppercase and lowercase hex letters.
MD5 was designed by Ronald Rivest in 1991 and produces a 128-bit hash. While it is no longer considered cryptographically secure due to collision vulnerabilities discovered in 2004, MD5 is still widely used for non-security purposes: file integrity checks (md5sum), database checksums, cache key generation, content deduplication, and Gravatar email hashing.
Examples include: d41d8cd98f00b204e9800998ecf8427e (the MD5 of an empty string) and 098f6bcd4621d373cade4e832627b4f6 (the MD5 of the word test). This pattern is useful for checksum validation, hash comparison tools, and data integrity verification applications.
Example Test Strings
| Input | Expected |
|---|---|
| d41d8cd98f00b204e9800998ecf8427e | Match |
| 098f6bcd4621d373cade4e832627b4f6 | Match |
| too-short | No Match |
| gggggggggggggggggggggggggggggggg | No Match |
| d41d8cd98f00b204e9800998ecf8427eFF | No Match |
Try It — Interactive Tester
17 charsFlags: noneMatches: 0Ctrl+Shift+C to copy regex
Related Regex Patterns
Regex to Match SHA-256 Hash Strings
/^[a-fA-F0-9]{64}$/
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