Match Address: mixing numbers and characters : Match Address « Regular Expressions « Java






Match Address: mixing numbers and characters

 

public class Main {
  public static void main(String args[]) {
    String addr = "street 124 a0a";
    String nameToken = "\\p{Upper}(\\p{Lower}+\\s?)";
    String namePattern = "(" + nameToken + "){2,3}";
    String zipCodePattern = "\\d{5}(-\\d{4})?";
    String addressPattern = "^" + namePattern + "\\w+ .*, \\w+ " + zipCodePattern + "$";
    System.out.println(addr.matches(addressPattern));

  }
}

 








Related examples in the same category

1.Match Email addressMatch Email address
2.Match address regular expressionsMatch address regular expressions