金额的正则表达式

//金额正则(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());

}

你可能感兴趣的:(java,正则)