gpt4 book ai didi

regex - 什么是 "The Best"美元正则表达式?

转载 作者:行者123 更新时间:2023-12-03 01:24:04 24 4
gpt4 key购买 nike

快速搜索货币正则表达式会出现 a lot of results .

我在选择一个时遇到的问题是,如果不测试所有边缘情况,正则表达式就很难验证。有人有经过彻底测试的美国货币正则表达式吗?

我唯一的要求是匹配的字符串是美国货币并解析为System.Decimal:

[ws][sign][digits,]digits[.fractional-digits][ws] Elements in square brackets ([ and ]) are optional. The following table describes each element. ELEMENT             DESCRIPTIONws                  Optional white space.sign                An optional sign.digits              A sequence of digits ranging from 0 to 9.,                   A culture-specific thousands separator symbol..                   A culture-specific decimal point symbol.fractional-digits   A sequence of digits ranging from 0 to 9. 

最佳答案

这是 Regex Buddy 的制作者提供的一些内容。这些来自图书馆,所以我相信它们已经过彻底的测试。

数字:货币金额(分必填)可选千位分隔符;强制两位数小数

Match; JGsoft:
^[+-]?[0-9]{1,3}(?:,?[0-9]{3})*\.[0-9]{2}$

数字:货币金额(分可选)可选千位分隔符;可选的两位数小数

Match; JGsoft:
^[+-]?[0-9]{1,3}(?:,?[0-9]{3})*(?:\.[0-9]{2})?$

数字:美国和欧盟的货币金额(分可选)可以使用美国式 123,456.78 表示法和欧洲式 123.456,78 表示法。可选千位分隔符;可选的两位数小数

Match; JGsoft:
^[+-]?[0-9]{1,3}(?:[0-9]*(?:[.,][0-9]{2})?|(?:,[0-9]{3})*(?:\.[0-9]{2})?|(?:\.[0-9]{3})*(?:,[0-9]{2})?)$

关于regex - 什么是 "The Best"美元正则表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/354044/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com