Skip to content

Commit 9b45730

Browse files
committed
Fix price extraction for four-digit amounts
1 parent a046c57 commit 9b45730

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

utils/test_text.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ def test_extract_decimal_prices_many() -> None:
2424
Decimal(122.00),
2525
Decimal(100.00),
2626
]
27+
28+
29+
def test_extract_decimal_prices_without_commas() -> None:
30+
assert extract_decimal_prices("$2110.00") == [Decimal(2110.00)]

utils/text.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
def extract_decimal_prices(text: str) -> list[Decimal]:
66
prices: list[Decimal] = []
7-
matches = re.findall(r"\$(\d{1,3}(?:,\d{3})*(?:\.\d{2}))?", text)
7+
matches = re.findall(
8+
r"\$((?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d{2}))",
9+
text,
10+
)
811
for match in matches:
912
prices.append(Decimal(match.replace(",", "")))
1013

0 commit comments

Comments
 (0)