正则表达式python查找金额和单词,以防金额放在段落的末尾

时间:2017-07-28 21:09:14

标签: python regex split words

我需要在每种情况下的金额和单词之后立即罚款金额和单词,然后我应该只有金额。情况是美元金额放在段落的末尾。 这是示例段落。

The cumulative effect resulted in a charge to incomeof $1,001.9 million 
(after  reduction for income taxes of $6.4 million) in fiscal2001. Assuming 
the accounting change had been applied retroactively by theCompany to prior 
periods, pro forma net loss for fiscal 2000 and pro forma netincome for 1999 
would have been ($17.3) million and $12.6 million, respectively.Net loss per
common share would have been ($0.57) in 2000, and net income perdiluted share 
would have been $0.42 in 1999. Fiscal 2001 would have been $255.5 million and 
net loss percommon share would have been ($0.02).

我想找到

 [$1,001.9 million, $6.4 million), ($17.3) million, $12.6 million, ($0.57) in, 
 $0.42 in, $255.5 million, ($0.02).]

1 个答案:

答案 0 :(得分:1)

如果没有正则表达式,您可以轻松完成此任务。

['$' + ' '.join(line.split(" ")[:2]) for line in text.split("$")[1:]]