我試圖在Python中編寫正則表達式來提取段落的一部分。正則表達式來提取段落
在下面的段落中,我希望提取的部分是粗體。
建議將提升救助資金,注入資金,銀行和削減 希臘債務說報告。
我正則表達式和輸出如下,
>>> text = 'Proposal will boost bailout fund, inject cash into banks and cut Greek debt says reports.'
>>> pattern = re.compile(r'(boost bailout)+?([\s\S]*?)(debt)+?')
>>> print re.findall(pattern, text)
[('boost bailout', ' fund, inject cash into banks and cut Greek ', 'debt')]
雖然它提取正確的部分,是不是該萃取被分離成3份在一個元組,而不是隻是一個單一的線如下面?
[('boost bailout fund, inject cash into banks and cut Greek debt')]
再次感謝!很多要學習,很多要學習。 :) – Ted
不客氣,再一次,特德! :) –