REGEXVAULTv2.0
Finance/Crypto
Verified Safe

Crypto Transaction Hash (Generic) Regex for Go

/^(?: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 Go. 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 Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.

Go Implementation

Go
// Crypto Transaction Hash (Generic)
// ReDoS-safe | RegexVault — Finance > Crypto

package validation

import "regexp"

var cryptoTransactionHashGenericRe = regexp.MustCompile(`^(?:0x)?[0-9a-fA-F]{64}$`)

func ValidateCryptoTransactionHashGeneric(s string) bool {
    return cryptoTransactionHashGenericRe.MatchString(s)
}

// Example
// fmt.Println(ValidateCryptoTransactionHashGeneric("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 Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. 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