十进制数的正则表达式

ali*_*fer 7 regex decimal

任何人都可以为长度在1到17之间的数字提供正则表达式,并且可以选择包含最多4个位置的尾数吗?长度17包括特征和尾数.

编辑:

长度为17不包括小数点.

有效示例:

12345678901234567 
1234567890123.4567 
123456789012345.67
12.34

无效:

12345678901234.5678 (Length of numerals = 18)

谢谢.

Ama*_*osh 5

^\d{17}$|^\d{13}(?=.{5}$)\d*\.\d*\d$
Run Code Online (Sandbox Code Playgroud)

正则表达式解释说:

^\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
Run Code Online (Sandbox Code Playgroud)