Вместо того, чтобы заменять нежелательный текст пустой строкой, это извлекает нужный текст.
>>> import re
>>>
>>> text = '''TABLE 37-1 Text over multiple
...: lines that describes the table (.pdf)
...: Non table text line 1.
...: Non table text line 2.
...: TABLE 37-2 Text over multiple
...: lines that describes the table (.pdf)'''
>>>
>>> re.match(r'TABLE.*?\(\.pdf\)\n(.*)TABLE.*?\(\.pdf\)$', text, re.DOTALL).group(1)
'Non table text line 1.\nNon table text line 2.\n'
Должно также работать, если в тексте, не являющемся таблицей, есть "TABLE ... (.pdf)"
строки.
>>> text = '''TABLE 37-1 Text over multiple
...: lines that describes the table (.pdf)
...: Non table text line 1.
...: Non table text line 2.
...: TABLE 37-2 non table text that
...: starts with TABLE and ends with (.pdf)(.pdf)
...: TABLE 37-2 Text over multiple
...: lines that describes the table (.pdf)'''
>>>
>>> re.match(r'TABLE.*?\(\.pdf\)\n(.*)TABLE.*?\(\.pdf\)$', text, re.DOTALL).group(1)
'Non table text line 1.\nNon table text line 2.\nTABLE 37-2 non table text that\nstarts with TABLE and ends with (.pdf)(.pdf)\n'