REGEXVAULTv2.0
Finance/Crypto
Verified Safe

Bitcoin Address (P2SH — starts with 3) Regex for Go

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

What this pattern does

This page provides a well-structured, multi-part regular expression for matching bitcoin address (p2sh — starts with 3), 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 (P2SH — starts with 3)
// ReDoS-safe | RegexVault — Finance > Crypto

package validation

import "regexp"

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

func ValidateBitcoinAddressP2shStartsWith3(s string) bool {
    return bitcoinAddressP2shStartsWith3Re.MatchString(s)
}

// Example
// fmt.Println(ValidateBitcoinAddressP2shStartsWith3("3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy")) // true

Test Cases

Matches (Valid)
Rejects (Invalid)
3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy1A1zP1eP5QGefi2DMPTfTL5SLmv7Divf
3Ai1JZ8pdJb2ksieUV8FsxSNVJCpoPi8W6bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq
2J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy

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

A P2SH address alone does not reveal the underlying script (multisig, timelock, etc.). To verify a multisig arrangement, you need the redeem script, not just the address.

Technical Notes

P2SH addresses start with 3. Commonly used for multisignature wallets and wrapped SegWit (P2SH-P2WPKH). More flexible than P2PKH — can represent complex spending conditions.

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