Код: Выделить всё
import re
source_string ="2025-05-22 08:15:41 - Lorum Ipsum One\n\n2025-05-23 09:12:27 - Lorum Ipsum Two\n\nAnother line of text\n\n2025-05-24 13:33:45 - Lorum Ipsum Three"
pattern = r"(\n\n\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})"
result = re.split(pattern, source_string)
Код: Выделить всё
['2025-05-22 08:15:41 - Lorum Ipsum One',
'\n\n2025-05-23 09:12:27 - Lorum Ipsum Two\n\nAnother line of text',
'\n\n2025-05-24 13:33:45 - Lorum Ipsum Three'
]
Код: Выделить всё
['2025-05-22 08:15:41 - Lorum Ipsum One',
'\n\n2025-05-23 09:12:27',
' - Lorum Ipsum Two\n\nAnother line of text',
'\n\n2025-05-24 13:33:45',
' - Lorum Ipsum Three'
]
Я не могу просто разделить на "\\n\\n", потому что некоторые из желаемых выходных строк являются многострочными (см. Lorum Ipsum Two)
Подробнее здесь: https://stackoverflow.com/questions/797 ... esult-list