Subject: | 'or' inside string() regex incorrectly matches everything |
When the word "or" exists inside a handler's string regex, it causes the regular expression to always evaluate to true.
In the attached code, I expect only the "Important:" line to be printed, but the "or" in "Important:" causes every <p> tag to match.
The surrounding content in the regex doesn't seem to matter, nor the content of the strings being matched.
Subject: | test.pl |
#!/usr/bin/perl
use strict;
use warnings;
use XML::Twig;
my $xhtml = <<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<html><body>
<h1><a name="CIHEHEAF"></a>Inserting Test Points</h1>
<p>line1</p>
<p>line2</p>
<p>Important</p>
<p>line3</p>
<p>line4</p>
</body></html>
EOF
my $twig=XML::Twig->new (
twig_handlers => {
'p[string()=~/^Impor/]' => \&p_note,
}
);
$twig->parse($xhtml);
sub p_note { print "NOTE:".$_->sprint."\n"; }