我試圖提取跨越多行的內容。內容是這樣的:在Python中使用正則表達式完全匹配多行
some content here
[1/1/2015 - SSR] something
[1/2/2015 - SSR] another:
*something here
*another something here
not relevant, should not be returned
[1/3/2015 - SSR] another one
總是有前*
的空間我使用的代碼是:
re.search(r'.*- SSR](.*)',line,re.DOTALL)
的預期結果是:
[1/1/2015 - SSR] something
[1/2/2015 - SSR] another:
*something here
*another something here
[1/3/2015 - SSR] another one
但它只能檢索第一個和第三個記錄,而不是第二個。由於它範圍多行。任何人都可以幫忙嗎?我真的很感激。
http://stackoverflow.com/questions/587345/python-regular-expression-matching-a-multiline-block-of-text – rockerBOO 2015-03-13 18:55:26
包括預期匹配在題。 – 2015-03-13 18:58:48