Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Perl如何自下而上读取HTML_Regex_Perl - Fatal编程技术网

Regex 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

因此,我有一个类似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</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