[Israel.pm] Regex question

bc.other bc.other at gmail.com
Wed Dec 24 05:32:32 PST 2008


#!/usr/bin/perl

my $block = <<EOF;
Title1
  text1
  text2
Title2
  text3
  text4
EOF

my @sp = split(/Title\d/, $block);
foreach my $i (@sp)
{
   chomp($i);
   print "$i\n-------------------";
}



-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf
Of Peter Gordon
Sent: Wednesday, December 24, 2008 1:41 PM
To: Perl in Israel
Subject: [Israel.pm] Regex question

Suppose I have the following code
my $text =<<EOF;
Title1
  text1
  text2
Title2
  text3
  text4
EOF

@blocks = $text =~ m!(^Title\S+.*?)(?=^Title|\Z)!mgs ;

The idea is to split the text into blocks. This code works, but the
lookahead requires repeating part of the first half of the regex.

Is there a shorter regex, without the repetition, that can do the same
thing?

Peter

_______________________________________________
Perl mailing list
Perl at perl.org.il
http://perl.org.il/mailman/listinfo/perl




More information about the Perl mailing list