Regular expression for finding currency values but not dates in text

前端 未结 3 508
误落风尘
误落风尘 2021-01-29 07:18

I have text like the following two example strings

this book was sold for 12.00 on 12.12.2010
he paid 12.12.2010 , and puchased an amount of 15.00
3条回答
  •  [愿得一人]
    2021-01-29 08:11

    You could use

    \d+\.\d{2}(?![.\d])
    

    if all you need is to distinguish between dates in exactly this format and currency amounts in exactly this format.

    This regex looks for the pattern digits, dot, two-digits but only if it's not followed by either another dot or another digit (to prevent the dates from matching).

    Quick PowerShell test:

    enter image description here

    Update for short dates in the form dd.mm.yy (just in case you need them):

    (?

    enter image description here

提交回复
热议问题