2017-07-28 68 views
-2

末尾的金額的地方我需要罰金美元金額和話後,在每個案件的金額和單詞不可用,那麼我應該只有美元金額。段落末尾的美元金額就是這種情況。 這是示例段落。正則表達式蟒蛇找到金額和字的情況下,在第

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

你到目前爲止嘗試了什麼? – nutmeg64

+0

你在這裏做了很多事情,在千位以及標點符號上變得複雜。我認爲這個正則表達式是不可靠的,因爲你從語言中挑選它。 – sln

+0

@ nutmeg64我試着用[\ $] {1} [\ d,] + \。?\ d {0,2}(\ w +) – MMM

回答

1

您可以輕鬆地做到這一點沒有正則表達式。

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