![]() |
regular expression - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: regular expression (/thread-28142.html) |
regular expression - pramod - Jul-07-2020 Hi, I have text data: Document We need to retrieve all the text and match the text from [DAT_23] system test //empty_line up to..... [ END ]we can use re.search. Once we retrieve the whole text. Please reply and suggestions. RE: regular expression - karkas - Jul-10-2020 I'm no expert but, since what you want to retrieve are a lot of lines, maybe you can just loop through the file lines, see if '[DAT_23]' is in one line, start retrieving, and then stop when you find '[ END ]'. If you think these substrings could actually appear somewhere else and "confuse" the program, you could use the regular expression to match them at the specific parts of the string (i.e. right at the beginning or end). |