user3472
user3472

Reputation: 303

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.

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

Upvotes: 0

Views: 197

Answers (1)

Liutprand
Liutprand

Reputation: 557

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?

Upvotes: 1

Related Questions