/^\d{1,2}(\.\d{1,2})?$/
This regular expression matches a decimal number with one or two digits before the decimal point, and optionally one or two digits after the decimal point.
Here is a breakdown of the different parts of the expression:
^- Matches the start of the string.\d{1,2}- Matches one or two digits (0-9).(\.\d{1,2})?- Matches an optional group that starts with a decimal point (\.) and is followed by one or two digits. The?at the end makes the group optional.$- Matches the end of the string.
Examples of valid matches for this regular expression include:
- 0.5
- 12
- 1.23
- 99.99
Examples of invalid matches include:
- 123 (too many digits before the decimal point)
- 0.1234 (too many digits after the decimal point)
- .5 (missing digits before the decimal point)
原文地址: https://www.cveoy.top/t/topic/twW 著作权归作者所有。请勿转载和采集!