HD Wallet Derivation Path (BIP-32 / BIP-44) Regex for Go
/^m(?:\/(?:[0-9]+\'?|[0-9]+h?))+$/What this pattern does
This page provides a well-structured, multi-part regular expression for matching hd wallet derivation path (bip-32 / bip-44), 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
// HD Wallet Derivation Path (BIP-32 / BIP-44)
// ReDoS-safe | RegexVault — Finance > Crypto
package validation
import "regexp"
var hdWalletDerivationPathBip32Bip44Re = regexp.MustCompile(`^m(?:\/(?:[0-9]+\'?|[0-9]+h?))+$`)
func ValidateHdWalletDerivationPathBip32Bip44(s string) bool {
return hdWalletDerivationPathBip32Bip44Re.MatchString(s)
}
// Example
// fmt.Println(ValidateHdWalletDerivationPathBip32Bip44("m/44'/0'/0'/0/0")) // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
m/44'/0'/0'/0/0 | m |
m/44'/0'/0' | 44'/0'/0'/0/0 |
m/0/0 | m//44'/0' |
m/44h/0h/0h/0/0 | m/44'/0'/ |
m/0' | M/44'/0'/0' |
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
Hardened keys (') provide better security but require the private key for child derivation. Never share the master private key or any parent private key from a path with hardened derivation.
Technical Notes
BIP-44 path: m / purpose' / coin_type' / account' / change / address_index. Apostrophe (') or 'h' suffix denotes hardened derivation. Bitcoin: m/44'/0'/0'. Ethereum: m/44'/60'/0'. Solana: m/44'/501'/0'.
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