任何人都可以为长度必须在 1 到 17 之间的数字提供正则表达式,并且可以选择包含最多 4 位的尾数吗? 17 的长度包括特征和尾数。
编辑:
17 的长度不包括小数点。
有效示例:
12345678901234567
1234567890123.4567
123456789012345.67
12.34
无效的:
12345678901234.5678(数字长度=18)
谢谢。
最佳答案
^\d{17}$|^\d{13}(?=.{5}$)\d*\.\d*\d$
正则表达式解释:
^\d{17}$ //A string of 17 digits
| //or
^\d{13} //13 digits followed by
(?=.{5}$) //5 characters, of which
\d*\.\d* //one is a decimal point and others are digits
\d$ //and the last one is a digit
关于十进制数的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2369109/