求java正则一枚

正数 不能大于100 小数点前只能有两位 可以有小数 也可不输入小数 小数最多为两位?
^[+]?(([1-9]\d{1,2}[.]?)|(0.))(\d{0,2})?$ 这个不对 哎.

嗯,你那样就允许大于100的三位数了

试试这个:
我这里允许小数以0结尾,表示“近似值”的时候需要。如果不希望这样,改改也行。

[code="java"]package regexptest;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexpTest2 {

public static void main(String[] args) {
    Pattern p = Pattern.compile("^[+]?(([1-9][0-9]?|0)(\\.[0-9]{1,2})?|100(\\.0{1,2})?)$");

    for (String txt : new String[] { "3.14", "31.41", "+3.14", "3.1", "42",
            "3", "-3.14", "100", "100.00", "100.01", "300", "3.141", "03.14"}) {
        Matcher m = p.matcher(txt);
        if (m.find()) {
            String result = m.group(0);
            System.out.println(result);
        } else {
            System.out.println(txt + " does not match");
        }
    }
}

}
[/code]
输出:
[quote]
3.14
31.41
+3.14
3.1
42
3
-3.14 does not match
100
100.00
100.01 does not match
300 does not match
3.141 does not match
03.14 does not match
[/quote]

非要用正则判断吗?
[code="java"]
String str = "56.67";
String strs = str.split(".");
try {
double num = Double.valueOf(str);
if (num > 0 && num <100 && (strs.length < 2 || strs.length ==2 && strs[1].length() <= 2) {
System.out.println("true");
} else {
System.out.println("false");
}
} catch (NumberFormatException) {
System.out.println("false");
}
[/code]