danj35 has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I've got a webpage I've passed to a variable and I need to take a section of text between one start and end point.

So for example I need everything between =Man= and =Woman= here:

=Man=

Is strong bla Is clever bla

=Woman=

Is probably not liking the comment stating that man is clever.

It would also be useful to take everything after =Woman= into a variable, without specifying an end point, so it would go all the way to the end of the page.

At the moment I can only get text between a start and end point on one line. Code for this is:

my $page = $mw->get_page( { title => $pagename } ); if(Dumper($page) =~ m/Daniel(.*?)world/) { print $1; }

Any help would be great, thanks.

Replies are listed 'Best First'.
Re: Searching string for paragraph..
by Ratazong (Monsignor) on May 06, 2010 at 12:59 UTC

    Have you tried the multiple-line modifier (m at the end of the regex)? See the entry in the PerlFAQ (part 6).

    if(Dumper($page) =~ m/Daniel(.*?)world/m) { print $1; }

    Update: moritz is right ... use s instead of m!
    Rata (who promises to be more concentrated next time)

      Although I don't understand the original question (mabye due to bad formatting?) I can tell that the /m modifier on your regex doesn't do anything - it merely affects ^ and $ to match line start/ending (instead of string start/ending).

      You probably meant the /s modifier instead, which makes . also match a newline.

      A reply falls below the community's threshold of quality. You may see it by logging in.