Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.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
匹配所有内容,直到精确div中的最后一个精确字符串(php)_Php_Html_Regex - Fatal编程技术网

匹配所有内容,直到精确div中的最后一个精确字符串(php)

匹配所有内容,直到精确div中的最后一个精确字符串(php),php,html,regex,Php,Html,Regex,我想匹配realty server上某个属性的地址。假设包含地址的div命名为,地址位于最后一个部分,如下所示: <body> <div class="price"> <h2> h2 </h2> </div> <div class="title"> <abcd> abcd </abcd> <efg>

我想匹配realty server上某个属性的地址。假设包含地址的div命名为
,地址位于最后一个
部分,如下所示:

<body>
  <div class="price">
    <h2>
      h2
    </h2>
  </div>      
  <div class="title">
    <abcd>
      abcd
    </abcd>
    <efg>
      efg
    </efg>
    <h2>
      adress
    </h2>
 </div>
</body>

氢
abcd
efg
地址
是否有一种可能的方法可以只通过一个正则表达式捕获地址,即使它将位于某个捕获的组中

我的无效解决方案是:

regex="/<div class="title">everything_except_<h2>*([^<]*)/";
regex=“/everything_,除了_*([^试试这个正则表达式:

<div class="title">(?:.(?!<\/div>))*<h2>([^<]*)

演示:

好吧,它对原始站点不起作用,看一看:@noctune注意
s
修饰符。@noctune:这是因为嵌套的
div
s。这是一个重要的条件,正则表达式需要进行一些调整才能考虑到它。你能告诉我为什么它不起作用吗?
/(?:(!)*([^@noctune:因为嵌套的
div
在第一次关闭时停止。请查看支持嵌套的
div
的更新答案。
<div class="title">(?:<div.*?<\/div>|.(?!<\/div>))*<h2>([^<]*)