in reply to split/matching/regex question

I would like to make use of the string that was matched by the regex in the split code
Then capture it (note the parens below):
my @entries = split /(<!--NEWENTRY\d{6}-->)/, $longstring
Now @entries will be interlaced with your delimiter string.

The PerlMonk tr/// Advocate

Replies are listed 'Best First'.
Re: Re: split/matching/regex question
by Art_XIV (Hermit) on Apr 14, 2004 at 20:23 UTC

    Expanding upon Roy Johnson's example:

    use strict; use warnings; my $longstring = "first<!--NEWENTRY889700-->second third<!--NEWENTRY86 +7530-->last"; my @entries = split /<!--NEWENTRY(\d{6})-->/, $longstring; print "@entries\n";

    prints:

    first 889700 second third 867530 last

    Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"