I have a chatlog file (
chat.tex), and would like to include different parts of it in different parts of my document.
I can extract the relevant parts I want using regular expressions, or string indexing, for example:
% 2021-12-30 00:00:00 First text of the day % 2021-12-30 00:00:01 Second text of the day % 2021-12-30 00:00:02 Third text of the day % 2021-12-30 00:00:03 Fourth text of the day
I would like to include in one part of the document all text between
% 2021-12-30 00:00:01 and
% 2021-12-30 00:00:03:
Second text of the day % 2021-12-30 00:00:02 Third text of the day
Ideally, to prevent multiple read requests to the
chat.tex file, its content should be stored as a variable, and one would get the text from that variable.
Code if this was python:
chat = open("chat.tex", "r").read() def extract(start, end): return chat[chat.index(start):chat.index(end)] extract('% 2021-12-30 00:00:01', '% 2021-12-30 00:00:03')
(This might be partially a duplicate of Parse a file with a regexp and return first match - but I do not understand the answer, and think it might be very outdated, and costly in my scenario. I also do not specifically intend to include a file based on line numbers \input only part of file, without losing SyncTeX support?)