USD Currency (Inline) in PY
Match US dollar amounts inline in text: `$1,234.56`, `$99`, `$1,000,000.00`.
Try it in the PY tester →Pattern
regexPY
\$\d{1,3}(?:,\d{3})*(?:\.\d{2})? (flags: g)Python (re) code
pyPython
import re
pattern = re.compile(r"\$\d{1,3}(?:,\d{3})*(?:\.\d{2})?")
input_text = "Total $1,234.56 plus tax of $99"
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
\$ matches the literal dollar sign. \d{1,3} matches the first 1–3 digits. (?:,\d{3})* matches additional thousands groups (comma + 3 digits). (?:\.\d{2})? optionally matches a decimal portion with exactly two digits (cents).
Examples
Input
Total $1,234.56 plus tax of $99Matches
$1,234.56$99
Input
Bonus $1,000,000.00 awardedMatches
$1,000,000.00
Input
no money mentionedNo match
—