我正在尝试匹配货币格式xxx.xxx.xxx,xx
,以下是一些有效格式的示例:
29.332.893,32
-29.332.893,32 // Podrían ser numero negativos
29.332.893,322313213123132
00
00,1212
394458,92 // Nótese que los puntos son opcionales
我有这个正则表达式:\b[0-9]+(([\\.][0-9]{3})*([\\,][0-9]+)*)*\b
问题是在下面的列表中它匹配我不感兴趣匹配的值:
10.98,09 // Matchea el 10 por un lado y 98,09 por el otro
10.980456 // Matchea el 10
00.2da02 // Matchea el 00
4,098.09 // Matchea 4,098 por un lado y 09 por el otro
121837182372133.321321313 // No debería matchear ya que los puntos es cada 3 numeros, ahora me matchea 121837182372133 por un lado, y 321321313 por el otro
我一直在搜索,但找不到只匹配有效格式的方法,因为我正在使用 Matcher,当出现无效格式时,我总是留下不应该考虑的数据。
笔记
金额可能以任何方式出现,例如,我在上面放置的有效格式列表可能如下所示(这些只是一些示例):
total: $ 29.332.893,32 // Con el signo y espacios
tosdaasdtal: -29.332.893,32
tosdaasdtal: 29.332.893,32 // Sin el signo pesos
total: 29.332.893,322313213123132 asasasaasdasd
to333tal: $00
toastal: $00,1212
total: $ 00
394458,92 // Solo
从已经非常感谢了。
有 2 种有效格式:
没有千位分隔符:
用点作为千位分隔符:
也就是说,将两个表达式放在一起:
而且,由于数字可以在文本中的任何位置,我们将确保它没有被另一个数字包围,既不是句点和数字,也不是逗号和数字。
也不在前面:
也没有发生:
正则短语
代码:
结果:
示范:
http://ideone.com/91hay3