@@ -224,11 +224,27 @@ def test_uri(data, expected):
224
224
@pytest .mark .parametrize ("data, expected" , MONEY_REGEX_TEST_CASES )
225
225
def test_money (data , expected ):
226
226
money_regex = re .compile ('|' .join ([
227
- r'^\$?(\d*\.\d{1,2})$' , # e.g., $.50, .50, $1.50, $.5, .5
228
- r'^\$?(\d+)$' , # e.g., $500, $5, 500, 5
229
- r'^\$(\d+\.?)$' , # e.g., $5.
230
- r'^\$?(\d+)(,\d{3})*$' , # e.g., $123,456, $1,234, $12,345
231
- r'^\$?(\d+)(,\d{3})*\.?$' , # e.g., $123,456.5, $1,234, $12,345
232
- r'^\$?(\d+)(,\d{3})*.\d{1,2}$' , # e.g., $123,456.5, $1,234, $12,345
227
+ r'^\$?(\d*\.\d{1,2})$' , # e.g., $.50, .50, $1.50, $.5, .5
228
+ r'^\$?(\d+)$' , # e.g., $500, $5, 500, 5
229
+ r'^\$? (\d+\.?)$' , # e.g., $5.
230
+ r'^\$?(\d+)(,\d{3})*$' , # e.g., $123,456, $1,234, $12,345
231
+ r'^\$?(\d+)(,\d{3})*\.?$' , # e.g., $123,456.5, $1,234, $12,345
232
+ r'^\$?(\d+)(,\d{3})*.\d{1,2}$' , # e.g., $123,456.5, $1,234, $12,345
233
233
]))
234
- assert expected == bool (re .match (money_regex , data ))
234
+ assert expected == bool (re .match (money_regex , data ))
235
+
236
+ def test_string_contains_money ():
237
+ money_regex = re .compile ('|' .join ([
238
+ r'\b\$?(\d*\.\d{1,2})' , # e.g., $.50, .50, $1.50, $.5, .5
239
+ r'\b\$?(\d+)' , # e.g., $500, $5, 500, 5
240
+ r'\b\$?(\d+\.?)' , # e.g., $5.
241
+ r'\b\$?(\d{1,3},\d{3})*' , # e.g., $123,456, $1,234, $12,345
242
+ r'\b\$?(\d{1,3},\d{3})*\.?' , # e.g., $123,456.5, $1,234, $12,345
243
+ r'\b\$?(\d{1,3},\d{3})*\.\d{1,2}' , # e.g., $123,456.5, $1,234, $12,345
244
+ ]))
245
+ str = "billed amount of $52,221,646.74."
246
+ result = re .findall (money_regex , str )#.groups()
247
+ #print(f"test_money result: {result}")
248
+ assert result
249
+ assert result [0 ]
250
+ assert re .match (money_regex , str )
0 commit comments