[Israel.pm] Regex question

Peter Gordon peter at pg-consultants.com
Wed Dec 24 03:40:57 PST 2008


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




More information about the Perl mailing list