Dirk80 has asked for the wisdom of the Perl Monks concerning the following question:
I have a big text file. I'm interested only in the beginning tag and the text between a beginning and an end tag.
textfile.txt
Any text is in this document. But I'm only interested in the text between a beginning and an end tag +. BEGIN_TAG_110 In this text I'm interested in. It can consist of several lines. Until the end tag. END_TAG and any other things I'm not interested in until the next begi +nning tag starts. Any other text. BEGIN_TAG_237 I need this text. END_TAG More text ...
The result should be like this:
# BEGIN_TAG_110: # In this text I'm interested in. # It can consist of several lines. Until the end tag. # # BEGIN_TAG 237: # I need this text.
I'd like to have the beginning tag as the key of a hash and the corresponding text as its string value.
I tried this regular expression:
m/^.*BEGIN_TAG_(\d+)(.*)END_TAG.*/s;But it works only with the last one. It seems to be too greedy. But my main problem is how not to get only one, but all.
I'm really interested in how it could be done in a good manner or for any hints from you. Thank you!!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Get text between start and end tag
by hippo (Archbishop) on Feb 27, 2024 at 11:12 UTC | |
by Dirk80 (Pilgrim) on Feb 27, 2024 at 11:42 UTC | |
|
Re: Get text between start and end tag
by Marshall (Canon) on Feb 27, 2024 at 11:27 UTC | |
by Dirk80 (Pilgrim) on Feb 27, 2024 at 11:56 UTC | |
|
Re: Get text between start and end tag
by tybalt89 (Monsignor) on Feb 27, 2024 at 15:26 UTC | |
|
Re: Get text between start and end tag
by perlfan (Parson) on Feb 29, 2024 at 05:08 UTC |