Search code examples
pythonregexsplitwords

regex python find amount and words in case that amount places at the end of paragraph


I need to fine dollar amount and words right after the amount in every case and of the words are not available, then I should have only dollar amount. It is the case that the dollar amount places at the end of paragraphs. This is sample paragraph.

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).

I want to find

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

Solution

  • You can accomplish this easily without regexes.

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