You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

支持带千分位的多种货币格式正则表达式优化咨询

Solution for Matching Decimal Numbers with Optional Thousand Separators

Got it, let's fix your regex to handle both basic decimal formats and numbers with dot-separated thousand groups. Here's a tested pattern that covers all your cases:

^\d+(?:\.\d{3})*,\d{2}$

Breakdown of the Pattern

Let's break down each part so you understand how it works:

  • ^ : Anchors the match to the start of the string (ensures we don't have extra characters before the number)
  • \d+ : Matches one or more digits (covers the base integer part, like 1, 10, 1000 from your original examples)
  • (?:\.\d{3})* : A non-capturing group that matches zero or more instances of a dot followed by exactly three digits. The * makes this part optional (so numbers without thousand separators still work), and the non-capturing group (?:...) keeps the regex efficient by not storing unnecessary match groups.
  • ,\d{2} : Matches the comma followed by exactly two digits (your original decimal part requirement)
  • $ : Anchors the match to the end of the string (ensures no extra characters come after the decimal part)

Valid Matches

This pattern will correctly match all your desired formats:

  • 1,00
  • 10,00
  • 100,00
  • 1000,00
  • 1.000,00
  • 10.000,00
  • 100.000.000,00

Invalid Matches (To Understand Boundaries)

These will not be matched, which is probably what you want:

  • 100.00,00 (Thousand separator group has only two digits)
  • 1.00,00 (Same issue as above)
  • 1000,0 (Only one digit after the comma)
  • ,00 (No integer part before the comma)
  • 1000.000 (Missing the comma and decimal part)

If you need to adjust for edge cases (like optional leading signs, or allowing whitespace), let me know—but this should cover exactly what you asked for!

内容的提问来源于stack exchange,提问作者None

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:08:15