in reply to Re: split/matching/regex question
in thread split/matching/regex question

...but not that simple regexp. He didn't indicate that there was only one delimiter in the string.
my @entries = $longstring =~ /(.*?)(?:<!--NEWENTRY(\d+)-->)/g;
This will interleave the data with the numbers from the delimiter.

Update: Thanks to kvale for pointing out that this drops trailing data. I cannot come up with a foolproof fix using only a pattern match capture. This one will keep all data, but will tack on a phantom (empty) delimiter entry if the line ends with data:

my @entries = $longstring =~ /(.*?)(?:<!--NEWENTRY(\d+)-->|$)/g;

The PerlMonk tr/// Advocate

Replies are listed 'Best First'.
Re: Re: Re: split/matching/regex question
by kvale (Monsignor) on Apr 14, 2004 at 20:29 UTC
    Good point regarding multiple delimiters, I was just working from his example.

    Your regexp, however, will miss the element after the last delimiter. Your split method in a following node is a better solution.

    -Mark