in reply to split/matching/regex question

Split discards the delimiter, so a better solution would be a simple regexp:
my @entries = $longstring =~ /^([^<]*)<!--NEWENTRY(\d+)-->([^>]*)$/;

-Mark

Replies are listed 'Best First'.
Re: Re: split/matching/regex question
by Roy Johnson (Monsignor) on Apr 14, 2004 at 20:16 UTC
    ...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
      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