金額の正規表現

3662 ワード

//    (18,2)
private static final String AMT_REGEX = "^(([1-9][0-9]{0,14})|([0]{1})|(([0]\\.\\d{1,2}|[1-9][0-9]{0,14}\\.\\d{1,2})))$";
private static final String INPUT = "0.11";

public static void main(String args[]) {
    //***matches
    boolean isMatch = Pattern.matches(AMT_REGEX, INPUT);
    System.out.println("matches:"+isMatch);

    //matcher
    Pattern pattern;
    pattern = Pattern.compile(AMT_REGEX);
    Matcher matcher = pattern.matcher(INPUT);
    //          
    System.out.println("lookingAt(): "+matcher.lookingAt());
    //       
    System.out.println("matches(): "+matcher.matches());

}