Skip to content

Instantly share code, notes, and snippets.

@mpurbo
Created January 21, 2012 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpurbo/1651260 to your computer and use it in GitHub Desktop.
Save mpurbo/1651260 to your computer and use it in GitHub Desktop.
Japanese Postcode Regular Expression
public static final String SPACE = "[\\s\u3000]";
public static final String NUMBER = "[0-9\uff10-\uff19]"; // 0-90-9
public static final String HYPHEN = "[-\uff0d\u2212]";
public static final String NOT_NUMBER_OR_HYPHEN = "[^" + NUMBER.substring(1, NUMBER.length()-1) + HYPHEN.substring(1);
public static final String REGEX_POSTCODE =
"(?:" + NOT_NUMBER_OR_HYPHEN.substring(0, NOT_NUMBER_OR_HYPHEN.length() - 1) + "\\)]|^)" +
"\u3012?" +
SPACE + "*(" + NUMBER + "{3})" +
SPACE + "*" + HYPHEN +
SPACE + "*(" + NUMBER + "{4})(?:" +
NOT_NUMBER_OR_HYPHEN.substring(0, NOT_NUMBER_OR_HYPHEN.length() - 1) + "\\(]|$)";
public static final Pattern PATTERN_POSTCODE = Pattern.compile(REGEX_POSTCODE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment