[Israel.pm] How to "split" but keep the delimiter

Yuval Yaari yuval at windax.com
Mon Dec 6 05:27:44 PST 2004

Yossi.Itzkovich at ecitele.com wrote:

>I know I can do it without "split", but still, by using split, how can I
>still leave the delimiter in the returned list ?
>For example:
>my @out=split (/instance No \d+/ , $text)
>I want to iterate over @out, but still having that \d in place
Do you want to keep only the \d+ or everything?
Try using a zero-width-positive-lookahead (?=).
my @out = split(/instance No (?=\d+)/, $text);

Good luck.


More information about the Perl mailing list