I’ve lots of 9-digit zip codes like shown below.
94107-1532
94107-1532
94107-1535
94107-1511
The first part is the first five digits of the zip code which indicates the destination post office or delivery area. The last 4 digits of the nine-digit ZIP Code represents a specific delivery route within that overall delivery area. I wanted to remove the last 4 digits starting including the Hyphen symbol(-
). I tried the below expression, but no luck!
public static String removeRoute(String zipCode) {
return zipCode.replaceAll("-\\d$", "");
}