用于在文本中查找货币值而不是日期的正则表达式 [英] Regular expression for finding currency values but not dates in text

查看:38
本文介绍了用于在文本中查找货币值而不是日期的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似以下两个示例字符串的文本

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

我想从这些行中获取金额,而不是使用正则表达式的日期.

From these lines I want to capture the amount, but not the dates using a regular expression.

推荐答案

你可以使用

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

如果您只需要区分完全这种格式的日期和完全这种格式的货币金额.

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

此正则表达式查找模式 digits, dot, two-digits 但前提是 not 后跟另一个点或另一个数字(以防止日期匹配).

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).

快速 PowerShell 测试:

Quick PowerShell test:

dd.mm.yy 形式更新短日期(以防万一):

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

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

这篇关于用于在文本中查找货币值而不是日期的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆