如何丢弃正则表达式组后的所有字符
我只想允许 2 位正双精度数。
我得到了这个,它正在工作,但是在我成功匹配模式后,它会重新开始,而不是丢弃传入的字符。
([1-9]+[\d]*(\.|,)?[\d]{0,2})
Input
12.34 //Pass Filter
12.340 //Rejected - Zero cannot be the first character
12.345 //Pass Filter - It pass, but it is supposed to be rejected since it has 3 decimal digits
I want to only allow a positive double with 2 digits.
I got this, which is working, but after I successfully match the pattern it starts over again instead of discarding incoming characters.
([1-9]+[\d]*(\.|,)?[\d]{0,2})
Input
12.34 //Pass Filter
12.340 //Rejected - Zero cannot be the first character
12.345 //Pass Filter - It pass, but it is supposed to be rejected since it has 3 decimal digits
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不想部分匹配,可以锚定字符串,并将零和逗号放入字符类中。
如果您想匹配
.
或,
零次或 1 次,您可以使用?
而不是*
请参阅正则表达式演示。
If you don't want partial matches, you can anchor the string, and put the zero and comma in a character class.
If you want to match the
.
or,
zero or 1 times you can use?
instead of*
See a regex demo.