US Currency (USD) in PY
Matches USD currency amounts with optional $ sign, thousands separators, and cents.
Try it in the PY tester →Pattern
regexPY
^\$?\d{1,3}(,\d{3})*(\.\d{2})?$Python (re) code
pyPython
import re
pattern = re.compile(r"^\$?\d{1,3}(,\d{3})*(\.\d{2})?$")
input_text = "$1,234.56"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
How the pattern works
`^\$?` optional dollar sign. `\d{1,3}(,\d{3})*` matches the integer part with optional comma-separated thousands. `(\.\d{2})?` optional cents.
Examples
Input
$1,234.56Matches
$1,234.56
Input
999Matches
999
Input
$1000000.00No match
—