REGEXVAULTv2.0
Security/Password Formats
Verified Safe

MD5 Hash (Deprecated — Detection Only) Regex for Python

/^[a-f0-9]{32}$/i

What this pattern does

This page provides a lightweight, single-purpose regular expression for matching md5 hash (deprecated — detection only), ported and verified for Python. In security-sensitive code, using an unverified regex can open the door to both false positives and denial-of-service attacks. The snippet below is ready to drop into your Python project — whether you're validating in a Django view, a FastAPI endpoint, or a standalone data processing script.

Python Implementation

Python
# MD5 Hash (Deprecated — Detection Only)
# ReDoS-safe | RegexVault — Security > Password Formats

import re

md5_hash_deprecated_detection_only_pattern = re.compile(r'^[a-f0-9]{32}$')

def validate_md5_hash_deprecated_detection_only(value: str) -> bool:
    return bool(md5_hash_deprecated_detection_only_pattern.fullmatch(value))

# Example
print(validate_md5_hash_deprecated_detection_only("d41d8cd98f00b204e9800998ecf8427e"))  # True

Test Cases

Matches (Valid)
Rejects (Invalid)
d41d8cd98f00b204e9800998ecf8427ed41d8cd98f00b204e9800998ecf8427
098f6bcd4621d373cade4e832627b4f6d41d8cd98f00b204e9800998ecf8427eX
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

When to use this pattern

This pattern is drawn from the Security > Password Formats category and carries a ReDoS-safe certification. That matters for Python developers because particularly important in Python web servers where CPU-bound regex operations can stall concurrent request handling. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

MD5 hashes of passwords can be cracked in milliseconds with GPU rainbow tables for passwords under 10 characters. A database of MD5-hashed passwords is effectively a plaintext database for short passwords.

Technical Notes

MD5 is cryptographically broken — collision attacks are trivial, preimage attacks are feasible. Never use MD5 for password hashing or security purposes. Use only for checksums where collision resistance is not required (e.g., non-security file deduplication). Include this pattern only for detection/migration purposes.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern