HD Wallet Derivation Path (BIP-32 / BIP-44) Regex for JavaScript
/^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 JavaScript. 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 JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.
Javascript Implementation
// HD Wallet Derivation Path (BIP-32 / BIP-44)
// ReDoS-safe | RegexVault — Finance > Crypto
const hdWalletDerivationPathBip32Bip44Regex = /^m(?:\\/(?:[0-9]+\'?|[0-9]+h?))+$/;
function validateHdWalletDerivationPathBip32Bip44(input: string): boolean {
return hdWalletDerivationPathBip32Bip44Regex.test(input);
}
// Example
console.log(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 JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. 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