REGEXVAULTv2.0
Finance/Crypto
Verified Safe

Bitcoin Address (Legacy P2PKH — starts with 1) Regex for Go

/^1[a-km-zA-NP-Z1-9]{25,34}$/

What this pattern does

This page provides a lightweight, single-purpose regular expression for matching bitcoin address (legacy p2pkh — starts with 1), 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
// Bitcoin Address (Legacy P2PKH — starts with 1)
// ReDoS-safe | RegexVault — Finance > Crypto

package validation

import "regexp"

var bitcoinAddressLegacyP2pkhStartsWith1Re = regexp.MustCompile(`^1[a-km-zA-NP-Z1-9]{25,34}$`)

func ValidateBitcoinAddressLegacyP2pkhStartsWith1(s string) bool {
    return bitcoinAddressLegacyP2pkhStartsWith1Re.MatchString(s)
}

// Example
// fmt.Println(ValidateBitcoinAddressLegacyP2pkhStartsWith1("1A1zP1eP5QGefi2DMPTfTL5SLmv7Divf")) // true

Test Cases

Matches (Valid)
Rejects (Invalid)
1A1zP1eP5QGefi2DMPTfTL5SLmv7Divf0A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
1BpEi6DfDAUFd153wiGrvkiKW1iHreNyZX3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy
1GKkRw6MhXD3Y23WLTV4gg4cS1Jp4bQqCbc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq
1A1zP1eP5QGefi2DMPTfTL5SLmv7Divf22

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

Bitcoin address format validation via regex cannot verify that the address actually belongs to an active wallet or that the checksum is correct. Always use a Bitcoin library for checksum validation.

Technical Notes

P2PKH addresses start with 1. Base58Check encoding (excludes 0, O, I, l to avoid confusion). Length is 25-34 chars. The address encodes a hash of the public key — validate the checksum with actual Base58Check decoding.

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