Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python regex to find text between headers

Consider the text:

HEADER
the cat
HEADER
the dog
HEADER
the bird

Using python attempting to construct a regex to extract the text between each HEADER section.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have tried:

results = re.findall(r’HEADER([\s\S]+)(?:HEADER||$))

This ends up capturing all the text in the capture group.

Assumption was the above regex would capture all text between to header blocks, or a header block and the end of file

>Solution :

I feel that in that specific case using a .split("HEADER") is easier then a regex. Do you specifically need a regex for some resason?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading