Repeating groups problem

Hi

I am trying to locate all strings seperated by the string -CR-, the string will have an unknown number of these -CR- strings, I've used the regex:

^(?:(.*?)-CR-)+$

As shown in the test code:

my ($myString)="This is the first line-CR-second line-CR-third line-CR-fourth line-CR-fifth line-CR-";
if ($myString =~ /^(?:(.*?)-CR-)+$/)
{
print "String1 $1 String2 $2 String3 $3 String4 $4 String5 $5\n";
}

However I only ever get the last line "fifth line" which goes to $1, it would seem that only $1 is ever set, and keeps getting overwritten. for example if I replace:

if ($myString =~ /^(?:(.*?)-CR-)+$/)

with:

if ($myString =~ /^(?:(.*?)-CR-){7,}$/)

As I expected I get no output as there only five repeats possible. If I change the 7 to number 5 or less than I again get the same last line found in $1, anyone got any ideas?

Thanks

Jon

Hi,
I have a different idea using cut.

> echo $myString
This is the first line-CR-second line-CR-third line-CR-fourth line-CR-fifth line-CR-

> echo $myString | sed 's/-CR-/:/g' | cut -d':' -f1-
This is the first line:second line:third line:fourth line:fifth line:

or you could get individual parts using f1,f2 etc....
i replaced the -CR- with : as a delimiter, because cut somehow refuses to accepts -CR- as a delimiter...

Thanks for your reply, unfortunately it doesn't help me, as I don't have a choice as to the delimiter, and I also have to do everything using a regex. It's a "very limited" programming language that uses perl regex,but has non of the other useful facilities.

BYTW I think if the - had been escaped then it would be accepted with cut.