REGEXVAULTv2.0
Finance/Crypto
Verified Safe

Crypto Transaction Hash (Generic) Regex for Python

/^(?:0x)?[0-9a-fA-F]{64}$/

What this pattern does

This page provides a lightweight, single-purpose regular expression for matching crypto transaction hash (generic), ported and verified for Python. Financial data validation has zero tolerance for false negatives — a missed invalid entry can corrupt downstream calculations. 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
# Crypto Transaction Hash (Generic)
# ReDoS-safe | RegexVault — Finance > Crypto

import re

crypto_transaction_hash_generic_pattern = re.compile(r'^(?:0x)?[0-9a-fA-F]{64}$')

def validate_crypto_transaction_hash_generic(value: str) -> bool:
    return bool(crypto_transaction_hash_generic_pattern.fullmatch(value))

# Example
print(validate_crypto_transaction_hash_generic("0xabcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"))  # True

Test Cases

Matches (Valid)
Rejects (Invalid)
0xabcdef0123456789abcdef0123456789abcdef0123456789abcdef01234567890x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1b
abcdef0123456789abcdef0123456789abcdef0123456789abcdef01234567890xabcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789a
a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2notahash
0xGGGG

When to use this pattern

This pattern is drawn from the Finance > Crypto 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

Transaction hashes are not globally unique across blockchains — the same hash string could theoretically appear on different chains (extremely unlikely but true). Include the chain identifier in your data model.

Technical Notes

Ethereum transactions use the 0x prefix. Bitcoin transactions do not. Both produce 256-bit (64 hex chars) hashes. Solana uses Base58-encoded 64-byte hashes — use a different pattern for Solana txids.

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