regular expression in iOS

前端 未结 4 1350
清酒与你
清酒与你 2020-12-06 05:44

I am looking for a regular expression to match the following -100..100:0.01. The meaning of this expression is that the value can increment by 0.01 and should b

4条回答
  •  清歌不尽
    2020-12-06 06:18

    (\b|-)(100(\.0+)?|[1-9]?[0-9](\.[0-9]{1,2})?\b
    

    Explanation:

    (\b|-)      # word boundary or -
    (           # Either match
     100        #  100
     (\.0+)?    #  optionally followed by .00....
    |           # or match
     [1-9]?     #  optional "tens" digit
     [0-9]      #  required "ones" digit
     (          #  Try to match
      \.        #   a dot
      [0-9]{1,2}#   followed by one or two digits
     )?         #   all of this optionally
    )           # End of alternation
    \b          # Match a word boundary (make sure the number stops here).
    

提交回复
热议问题