Street Address (US Format) Regex for Java
/^[0-9]{1,6}(?:\s+(?:apt|unit|ste|suite|#)\s*[A-Za-z0-9]+)?\s+[A-Za-z0-9\s.'-]{3,50}(?:\s+(?:ave|avenue|blvd|boulevard|ct|cir|dr|drive|hwy|highway|ln|lane|pkwy|parkway|pl|place|rd|road|st|street|ter|terrace|trl|trail|way))?\.?$/iWhat this pattern does
This page provides a comprehensive, battle-tested regular expression for matching street address (us format), ported and verified for Java. Identity and credential patterns need both correctness and safety, since they're frequent targets for adversarial input. 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
// Street Address (US Format)
// ReDoS-safe | RegexVault — Identity & PII > Location PII
import java.util.regex.Pattern;
public class StreetAddressUsFormatValidator {
private static final Pattern PATTERN =
Pattern.compile("^[0-9]{1,6}(?:\\s+(?:apt|unit|ste|suite|#)\\s*[A-Za-z0-9]+)?\\s+[A-Za-z0-9\\s.\'-]{3,50}(?:\\s+(?:ave|avenue|blvd|boulevard|ct|cir|dr|drive|hwy|highway|ln|lane|pkwy|parkway|pl|place|rd|road|st|street|ter|terrace|trl|trail|way))?\\.?$");
public static boolean validate(String input) {
return PATTERN.matcher(input).matches();
}
// Example
public static void main(String[] args) {
System.out.println(validate("123 Main St")); // true
}
}Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
123 Main St | Main St |
456 Elm Avenue | 123 |
789 Oak Blvd | Just A Name |
1000 Willow Lane Apt 5B | — |
1 Infinite Loop | — |
123 Main | — |
When to use this pattern
This pattern is drawn from the Identity & PII > Location PII 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
Address validation regex cannot verify that an address is deliverable. Use USPS CASS-certified address validation for mail delivery. For geocoding, use a geocoding API (Google Maps, Here).
Technical Notes
US addresses are extremely varied — this pattern covers the most common format but not all. PO Boxes, rural routes, and military addresses require different patterns. Use a dedicated address validation API (USPS, SmartyStreets) for reliable validation.
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