Python regex for dollar amounts including commas and decimals -
i'm new python , i'm writing bit of code needs take block of text , remove that's not dollar amount. example, number 2 thousand may represented 2000 2000.00 2,000 , 2k. i'm trying accomplish single regex replacement.
right have:
f=re.sub([0-9]+?(,[0-9])*?[0-9]+?(.[0-9])*?[ttbbmmkk],"",f)
while understand incorrect , not compile, i'm not proficient enough know it. can give me guidance? thanks!
give shot:
import re blockoftext = 'two thousand may represented 2000 2000.00 2,000 , 2k' ' '.join([ ''.join(x[0]) x in re.findall(r'(\$?\d+([,\.]\d+)?k?)', blockoftext) ])
that gets new text string assign blockoftext
if want, removing that's not dollar amount.
Comments
Post a Comment