Home > Archive > PERL Miscellaneous > October 2006 > It's regex time again - bigger and badder than ever before
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
It's regex time again - bigger and badder than ever before
|
|
|
| Hi everyone,
I have a text line that looks something like the following.
text1
text2
HEADER_1
interesting stuff
HEADER_2
text3
text4
text5
HEADER_3
more interesting stuff
....
HEADER_4
text6
text7
HEADER_3
even more interesting stuff
HEADER_4
text8
text9
HEADER_1
unbelievably interesting stuff
HEADER_2
HEADER_1 and HEADER_2 are corresponding opening and closing tags for one
type of content, with a similar arrangement for HEADER_3 and HEADER_4.
It is possible to write a regex to match either HEADER_1 or HEADER_3, but
can this be extended to match the content, and HEADER_2 and HEADER_4? Is it
possible to write a single regex to match either HEADER_1 or HEADER_3
followed by content followed by the corresponding HEADER_2 or HEADER_4 which
depends on whether HEADER_1 or HEADER_3 was matched?
I need to grab everything between HEADER_1 and HEADER_2, and everything
between HEADER_3 and HEADER_4, while keeping it in order. What would be the
simplest and/or cleanest way of doing this?
Thanks.
C3
| |
| Tad McClellan 2006-10-30, 7:10 pm |
| "C3" <"C3"> wrote:
> I have a text line that looks something like the following.
[snip]
> I need to grab everything between HEADER_1 and HEADER_2, and everything
> between HEADER_3 and HEADER_4, while keeping it in order. What would be the
> simplest and/or cleanest way of doing this?
The way that the Perl FAQ suggests.
perldoc -q lines
How can I pull out lines between two patterns that are themselves on dif‐
ferent lines?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
|
|
|
|
|