Ethereum Address Regex for Go
/^0x[0-9a-fA-F]{40}$/What this pattern does
This page provides a lightweight, single-purpose regular expression for matching ethereum address, 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
// Ethereum Address
// ReDoS-safe | RegexVault — Finance > Crypto
package validation
import "regexp"
var ethereumAddressRe = regexp.MustCompile(`^0x[0-9a-fA-F]{40}$`)
func ValidateEthereumAddress(s string) bool {
return ethereumAddressRe.MatchString(s)
}
// Example
// fmt.Println(ValidateEthereumAddress("0x742d35Cc6634C0532925a3b844Bc454e4438f44e")) // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
0x742d35Cc6634C0532925a3b844Bc454e4438f44e | 742d35Cc6634C0532925a3b844Bc454e4438f44e |
0x0000000000000000000000000000000000000000 | 0x742d35Cc6634C0532925a3b844Bc454e4438f44 |
0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2 | 0x742d35Cc6634C0532925a3b844Bc454e4438f44eXX |
| — | 0xGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG |
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
The null address (0x0000...0000) is a valid Ethereum address but tokens sent to it are unrecoverable (burned). Always validate the checksum for user-entered addresses to prevent typos.
Technical Notes
Case-insensitive for format validation. EIP-55 checksum encoding uses mixed case — 0xAb8483... is a checksummed address. Validate checksum with web3.utils.isAddress() or ethers.js utils.getAddress().
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