Regex Perl如何自下而上读取HTML
因此,我有一个类似Perl的HTML设置主体:Regex Perl如何自下而上读取HTML,regex,perl,Regex,Perl,因此,我有一个类似Perl的HTML设置主体: $html = "<html> <p>This is <div>some</div> text</p> <br><br> <p>This is <div>second</div> line text</p> <br><br> <p>This is <div>third&l
$html = "<html>
<p>This is <div>some</div> text</p>
<br><br>
<p>This is <div>second</div> line text</p>
<br><br>
<p>This is <div>third</div> line text</p>
</html>";
$html=”
这是一些文本
这是第二行文字
这是第三行文字
";
默认情况下,当我使用perl脚本(以匹配)时,它从上到下读取HTML。
以下是我的perl脚本的“匹配”部分:
my ($cropped_data) = ($html =~ /div[^>]*>([^<]+)/);
# $cropped_data will return 'some'
my($cropped_data)=($html=~/div[^>]*>([^这里有一个解决方案,可以反转$html
变量的行
$html = "<html>
<p>This is <div>some</div> text</p>
<br><br>
<p>This is <div>second</div> line text</p>
<br><br>
<p>This is <div>third</div> line text</p>
</html>";
$html = join ("\n",reverse(split /\n/, $html));
my ($cropped_data) = ($html =~ /div[^>]*>([^<]+)/);
print $cropped_data
允许您修改内存中的$html
变量吗?您可以在表达式开头添加*
(与's'点匹配所有修饰符组合),以强制正则表达式引擎从字符串结尾开始回溯,如下所示:$html=~/.*>([^@ridgerunner啊,我明白了,谢谢,
third