Search code examples
javaregexsanitizationprivacystreet-address

How would you sanitize the street number out of a postal address using Java?


To ensure data privacy, I have to publish a list of addresses after removing the street numbers.

So, for example:

1600 Amphitheatre Parkway, Mountain View, CA

needs to be published as

Amphitheatre Parkway, Mountain View, CA

What's the best way to do this in Java? Does this require regex?


Solution

  • EDIT : How about...

    addressString.replace("^\\s*[0-9]+\\s+","");
    

    or JavaScript...

    addressString.replace(/^\s*[0-9]+\s+/,'');
    

    My original suggestion was (JavaScript)...

    addressString.replace(/^\s*[0-9]+\s*(?=.*$)/,'');