REGEXVAULTv2.0
Finance/Crypto
Verified Safe

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

/^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 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

Java
// Bitcoin Address (P2SH — starts with 3)
// ReDoS-safe | RegexVault — Finance > Crypto

import java.util.regex.Pattern;

public class BitcoinAddressP2shStartsWith3Validator {
    private static final Pattern PATTERN =
        Pattern.compile("^3[a-km-zA-HJ-NP-Z1-9]{25,34}$");

    public static boolean validate(String input) {
        return PATTERN.matcher(input).matches();
    }

    // Example
    public static void main(String[] args) {
        System.out.println(validate("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 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

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