HD Wallet Derivation Path (BIP-32 / BIP-44) Regex for Java
/^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 Java. 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 Java project — whether you're validating in a Spring Boot controller, a Jakarta EE service, or a standalone utility class.
Java Implementation
// HD Wallet Derivation Path (BIP-32 / BIP-44)
// ReDoS-safe | RegexVault — Finance > Crypto
import java.util.regex.Pattern;
public class HdWalletDerivationPathBip32Bip44Validator {
private static final Pattern PATTERN =
Pattern.compile("^m(?:\\/(?:[0-9]+\\\'?|[0-9]+h?))+$");
public static boolean validate(String input) {
return PATTERN.matcher(input).matches();
}
// Example
public static void main(String[] args) {
System.out.println(validate("m/44'/0'/0'/0/0")); // true
}
}Test 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 Java developers because critical in Java applications since the JVM regex engine uses backtracking and is susceptible to ReDoS without careful pattern design. 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