在两个RegEx中打印文本

时间:2012-05-17 20:22:49

标签: html perl

如何从出现时开始打印文本 reg表达式$ STARTs REGEX直到$ 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

1 个答案:

答案 0 :(得分:1)

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

To the current program(.*)Please choose

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

Here is the rubular

对于更多perl-cut-and-paste(from this SO question

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

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