我正在尝试创建一个正则表达式模式来替换所有无效字符。
在小数点之前和小数点之后,我可以有任何类型的数字,例如:0.0,1.0,150.0,129.000,200.999等...
我有一个以下验证正则表达式模式,我用于验证和匹配:
"\\d+(\\.\\d+)*"
但是我想创建正则表达式模式,我可以使用它来验证十进制数并替换所有无效字符或意外字符,方法是使用.string.replaceAll("regex", value);
请在我的测试值下方检查,以及在替换所有无效字符后,它应该返回的结果。
String[] values = {
"0", // return 0 - valid
"0.", // return 0. - valid
"0.0", // return 0.0 - valid
"0.0.", // return 0.0 - invalid, because we dont expect another decimal point
"0.00", // return 0.00 - valid
"0.00.", // return 0.00 - invalid, because we dont expect antoher decimal point
"0.000", // return 0.000 - valid
// etc.
"10.000.", // return 10.000, this case should not be possible to enter because we dont want 2 decimal point so number like 10.000.00 should not be possible
"0.0/", // return 0.0, invalid -- any kind of character will be replaced with empty
"0.0@", // return 0.0, invalid -- any kind of character will be replaced with empty
};
蓝山帝景
相关分类