RegEx needed to match number to exactly two decimal places

后端 未结 5 1389
醉梦人生
醉梦人生 2020-12-06 09:48

I need some regex that will match only numbers that are decimal to two places. For example:

  • 123 = No match
  • 12.123 = No match
  • 12.34 = Match
5条回答
  •  既然无缘
    2020-12-06 10:40

    If you're looking for an entire line match I'd go with Paul's answer.

    If you're looking to match a number witihn a line try: \d+\.\d\d(?!\d)

    • \d+ One of more digits (same as [0-9])
    • \. Matches to period character
    • \d\d Matches the two decimal places
    • (?!\d) Is a negative lookahead that ensure the next character is not a digit.

提交回复
热议问题