Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I need to extract the data between each /BEGIN/ and /END/ from the string. The amount of sub-data records are variable but always given by a NEXT.$_ = "10001 LONG RECORD\n BEGIN RECORD A, CODE B, TABLE C END \n NEXT\n STANDARD DATA 1 BEGIN CODE A, RECORD B END NEXT\n SHORT RECORD BEGIN TABLE B END NEXT\n STANDARD DATA 2 BEGIN CODE C, RECORD D, FILE END;";
I'm thinking of writing a loop to match each group of expressions. But how do I count the amount of NEXT's in the string? Also how do I get the next set of /BEGIN/ /END/ expressions?
Final Regex question: I have the following in $1 = "CODE C, RECORD D, FILE";
How do I separate the 1st item from the the second, between comas. I.E. I want to have "CODE RECORD FILE" in one Array and "C D" in another. I thought the following would work:
(@recordSource, @recordType) = split(/\s/, split(/,/, $1));
But I only get a number in @recordSource.
Any tips or suggestions would be appreciated! Maybe I need a different approach?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multiple RegEx Matches in a single string
by broquaint (Abbot) on May 14, 2003 at 15:09 UTC | |
by chip (Curate) on May 14, 2003 at 16:13 UTC | |
|
Re: Multiple RegEx Matches in a single string
by Fletch (Bishop) on May 14, 2003 at 15:27 UTC |