[英]Regular expression - amount with comma and decimal
^([1-9][0-9]*|0)(\.[0-9]{2})?$
From above regular expression: 从正则表达式上面:
Now I want to add the comma into my regular expression as below: 现在我想将逗号添加到我的正则表达式中,如下所示:
How should I correct my regular expression? 我该如何纠正我的正则表达式?
In your regular expression you need to change 在正则表达式中,您需要更改
[1-9][0-9]*
which stand for "one or more digits starting from non-zero", to 代表“从非零开始的一个或多个数字”,到
[1-9][0-9]{0,2}(,[0-9]{3})*
which stands for "one to three digits starting from non-zero [1-9][0-9]{0,2}
, followed by any numbers of groups with three digits each (,[0-9]{3})*
". 表示“从非零[1-9][0-9]{0,2}
开始的一到三位数字,后跟任意数量的每组三位数的组(,[0-9]{3})*
“。
The resulting regular expression will be: 结果正则表达式为:
^([1-9][0-9]{0,2}(,[0-9]{3})*|0)(\.[0-9]{2})?$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.