Regex to match 2 digits, optional decimal, two digits

后端 未结 11 1370
时光取名叫无心
时光取名叫无心 2020-11-30 09:29

I\'ve spent half an hour trying to get this, maybe someone can come up with it quickly.

I need a regular expression that will match one or two digits, followed by an

11条回答
  •  悲&欢浪女
    2020-11-30 10:07

    You mentioned that you want the regex to match each of those strings, yet you previously mention that the is 1-2 digits before the decimal?

    This will match 1-2 digits followed by a possible decimal, followed by another 1-2 digits but FAIL on your example of .33

    \d{1,2}\.?\d{1,2}
    

    This will match 0-2 digits followed by a possible deciaml, followed by another 1-2 digits and match on your example of .33

    \d{0,2}\.?\d{1,2}
    

    Not sure exactly which one you're looking for.

提交回复
热议问题