我需要在一個段落中同時找到美元金額和少數(3或4)圍繞該金額的單詞。正則表達式Python在同一時間找到美元金額和幾個字
in-process research and development of $184.3 million and charges $120 of
million for the impairment of long-lived assets. See Notes 2, 16 and21 to the
Consolidated Financial Statements. Income from continuingoperations for the
fiscal year ended September 30, 2001 also includes a netgain on sale of
businesses and investments of $276.6 million and a net gainon the sale of
common shares of a subsidiary of $64.1 million.
我想要得到的是類似下面, [金額,金額+數字的話,3-4個單詞量之前後。
[$184.3 $184.3 million, research and development of $184.3 million],[$120, $120 of million,charges $120 of
million for the impairment of long-lived assets ], [$276.6, $276.6 million, investments of $276.6 million] ,[ $64.1, $64.1 million, a subsidiary of $64.1 million.]
我試過的是這個,它只發現美元的金額。
[\$]{1}\d+\.?\d{0,2}
謝謝!
你發現了美元的金額,你可以使用它的索引和字符串切片來找到圍繞它的文字 – anon
希望你想要的輸出我不認爲是必要的只是正則表達式,這是關閉的:'([^ \ S] + \砂\ S [^ \ S] + \ S)?([^ \ S] + \ S)([\ $ {1} \ d + \。?\ d {0,2})([ \ w \ s] * illion)' – depperm