regexp-货币字符串与小数和千位分隔符匹配

时间:2019-01-28 10:55:14

标签: php regex

/(?<!\d[- ]|[\d.,])-?[1-9]\d{0,2}(?:(?:[., ]\d{3})*|\d*)(?![\d%]|[- ][\d%])/

主题

812,30
48 kdk 1
54%
1.393.434 test
2.392,39
2,292.39

我不想将任何金额与小数匹配。因此,行812,302.392,392,292.39不应该匹配。

https://regex101.com/r/XPgypx/2

1 个答案:

答案 0 :(得分:1)

只需通过添加排除它们的否定前瞻来排除它们。

(?!.*,.*\.*)用于2,292.39搜索,而{{11}}用于(?!.*\..*,*)搜索

2.392,39

在此处进行测试:https://regex101.com/r/XPgypx/4