Trying to build a regular expression to check pattern

后端 未结 7 746
我在风中等你
我在风中等你 2021-01-20 17:32

a) Start and end with a number
b) Hyphen should start and end with a number
c) Comma should start and end with a number
d) Range of number should be from 1-31

相关标签:
7条回答
  • 2021-01-20 18:26

    Using the same logic in my previous answer but limiting the range

    A becomes [1-9]\d|3[01] B becomes ([1-9]\d|3[01])|(([1-9]\d|3[01])-([1-9]\d|3[01]))

    Overall expression

    (([12]\d|3[01])|(([12]\d|3[01])-([12]\d|3[01])))(,(([12]\d|3[01])|(([12]\d|3[01])-([12]\d|3[01]))))*

    0 讨论(0)
提交回复
热议问题