bryan
bryan

Reputation: 305

Python regular expressions ignoring commas in a long number

I am trying to figure out how to ignore commas in a long number, some the numbers are in the 0's to 10 million so I need something that can capture numbers from 0 to 10,000,000 and ignore commas. I am not sure how to go about this. Thanks

#Here is the pattern that contains the information I am looking for
Median Sales Price\n$1,417,000

# here is my pattern 
median_sales_price = re.findall(r'\bMedian Sales Price\n\$(\d*\,\d*\,\d*)',data)

Upvotes: 0

Views: 237

Answers (1)

Amadan
Amadan

Reputation: 198314

You can't. One capture captures one continuous substring. Capture with commas, then filter the commas out later.

median_sales_price = [re.sub(',', '', price) for price in
    re.findall(r'\bMedian Sales Price\n\$([\d,]+)', data)]

Upvotes: 1

Related Questions