0

我是正则表达式的新手,真的很难让它发挥作用。

我正在尝试从以下 html 之间的页面中获取一些信息:

<!--webbot bot="Include" U-Include="/inspections/Restaurants_Avalon.html" TAG="BODY" startspan --> EVERYTHING IN BETWEEN<!--webbot bot="Include" i-checksum="41417" endspan -->

我试过了:

$pattern = '/<.*?webbot bot=\"Include\" U-Include=\".*?\".*?startspan.*?(.*?)<.*?webbot bot=\"Include\" i-checksum=\".*?\" endspan.*?/i';

和其他几十种变体,但我明显缺乏对正则表达式的经验和理解,这只会造成常规混乱而不是表达式。

有人可以看看并告诉我我做错了什么吗?

谢谢!

4

1 回答 1

0

只需更改这部分:

startspan.*?(.*?)<.*?webbot

经过

startspan -->(.*?)<!--webbot

在行动:

$str = '<!--webbot bot="Include" U-Include="/inspections/Restaurants_Avalon.html" TAG="BODY" startspan --> EVERYTHING IN BETWEEN<!--webbot bot="Include" i-checksum="41417" endspan -->';

$pat = '/<.*?webbot bot=\"Include\" U-Include=\".*?\".*?startspan -->(.*?)<!--webbot bot=\"Include\" i-checksum=\".*?\" endspan.*?/i';

preg_match($pat, $str, $m);
print_r($m);

输出:

Array
(
    [0] => <!--webbot bot="Include" U-Include="/inspections/Restaurants_Avalon.html" TAG="BODY" startspan --> EVERYTHING IN BETWEEN<!--webbot bot="Include" i-checksum="41417" endspan
    [1] =>  EVERYTHING IN BETWEEN
)
于 2013-05-15T10:01:52.827 回答