Link to home
Start Free TrialLog in
Avatar of Tolgar
Tolgar

asked on

How to parse a text starting with a flag till another special flag?

How can I parse this in Perl?

AA: something in here
and it continues in the next 
and the third
and the n number of lines till the next flag
BB: some new text is here
CC: some other text is also here

Open in new window


This text can also be in this format:

BB: some new text is here
AA: something in here
and it continues in the next 
and the third
and the n number of lines till the next flag
CC: some other text is also here

Open in new window


AA: BB: CC: are the flags.

The expected output is:
something in here
and it continues in the next 
and the third
and the n number of lines till the next flag

Open in new window



The idea for this can be:

Parse everything that starts with AA: till (BB: or CC:)

How can I do that in Perl?

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tolgar
Tolgar

ASKER

If this is my original code: (The more complex form of this question is in ID: 27388059)

/^C(S|omments):\s*(.*\n)/ && push(@CS, $2) && goto CHECK;

Open in new window


Can I change it like this with your code in stead of new line character:

/^C(S|omments):\s*(\s*// .. s/\s*(RR|CR|Mail sent to):.*)/ && push(@CS, $2) && goto CHECK;

Open in new window


The thing that I wanna parse is in these formats:

CS:  some text in here
and continues in here
RR:something in here
CR: something in here

Mail sent to: some other thing

Open in new window



or

RR:something in here
CS:  some text in here
and continues in here
CR: something in here


Mail sent to: some other thing

Open in new window


or

RR:something in here
CR: something in here
CS:  some text in here
and continues in here

Mail sent to: some other thing

Open in new window




The part that I wanna capture is:
sometext in here
and continues in here

Open in new window


Do you think it is ok?

Thanks,

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.