Created
January 21, 2012 04:18
-
-
Save mpurbo/1651260 to your computer and use it in GitHub Desktop.
Japanese Postcode Regular Expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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