0

As per the title.

Matches should include any number in the range 1 - 365

with two digits after comma between 0 and 99 (so from __,00 to __,99).

Remark: the range can stop at 365,00 as well at 365,99, whichever is the easiest to implement.

Many thanks in advance for any help you might provide and Happy New Year.

Radeon89
  • 17
  • 7
  • Please note that requirements-only questions are not received well on this site. If you need help you should try to show us what you have tried and where you are stuck. In addition, regex is a poor choice for this sort of validation, and, if you are using a programming language, using an inequality check on the input would probably work much better. – Tim Biegeleisen Jan 05 '21 at 14:55
  • See https://jsfiddle.net/wiktor_stribizew/p03qarkt/1/, generate whatever range pattern you need. – Wiktor Stribiżew Jan 05 '21 at 15:13

1 Answers1

1

1,00 – 365,99

\b([1-9]|[1-9][0-9]|[12][0-9][0-9]|3[0-5][0-9]|36[0-5]),[0-9][0-9]\b

Explanation:

  • \b: This matches a word boundary, ensuring that the input will not match substrings such as "The number 12345,6789 should not be considered to contain a valid match."

  • [0-9]: This matches any digit between 0 and 9. Similarly, [0-5] matches any digit between 0 and 5. [12] (without a dash) matches either the digit 1 or the digit 2.

  • |: This delimits possible subexpressions, any one of which would be a valid match. The above regular expression uses the following subexpressions to match against the full range of numerical values represented by the input:

    • [1-9]: values less than 10
    • [1-9][0-9]: values between 10 and 99
    • [12][0-9][0-9]: values between 100 and 299
    • 3[0-5][0-9]: values between 300 and 359
    • 36[0-5]: values between 360 and 365
  • ,[0-9][0-9]: Finally, this matches a literal comma followed by any two digits.

1,00 – 365,00

\b(([1-9]|[1-9][0-9]|[12][0-9][0-9]|3[0-5][0-9]|36[0-4]),[0-9][0-9]|365,00)\b

This uses the previous regular expression adapted to match numeric strings representing values between 1,00 and 364,99, to which 365,00 is appended as a final valid possible match.

CJK
  • 5,732
  • 1
  • 8
  • 26