我们需要一个正则表达式,它应该接受最多2个小数点的有效十进制数字,并且选项包含在左右括号中
有效示例: 45.78 99.34 12202.45 (45.22) (65.00) (1255.00)
任何人都可以帮助我们解决这个问题。
答案 0 :(得分:1)
^(\d+(?:\.\d{1,2})?)$|^(\(\d+(?:\.\d{1,2})?\))$
^ //Start of string
( // Start capturing group
\d+ // Digit 1 or more times
(?: // Start Non capturing group
\. // Dot
\d{1,2} // Digit 1 to 2 times
)? // End non capturing group and ? means conditional
) // End capturing group
$ //End of string
| //OR (Now we check for numbers enclosed in parenthesis)
^ //Start of string
( // Start capturing group
\( // Match Left Parenthesis
\d+(?:\.\d{1,2})? // Same as above
\) // Match Right Parenthesis
) // End capturing group
$ //End of string