0

How can I print the text starting at the occurence of the reg expression $START_REGEX till $END_REGEX?

#!/usr/bin/perl -w

use strict;
use warnings;

package HTMLStrip;
use base "HTML::Parser";
use LWP::Simple;

my $START_REGEXP = 'To the current program';
my $END_REGEXP = 'Please choose';

sub text {
    my ($self, $text) = @_;
    print $text;
}

my $p = new HTMLStrip;
$p->parse_file("index.html");
$p->eof
4

1 回答 1

1

您可以只使用组来获取两个短语之间的值:

To the current program(.*)Please choose

然后,该值将存储在$1,$2, etc

这是红字

对于更多perl-cut-and-paste的东西(来自this SO question

my @values = ($text=~/$START_REGEXP(.*)$END_REGEXP/gm);
print "The first value is $values[0]\n";

我不是 PERL 开发人员,所以我在推断。如果某种语法关闭,您将不得不自己做进一步的研究。

于 2012-05-17T20:26:37.253 回答