0

我想创建一个正则表达式来接收:

<p class="MyClass">
   <p> something 1 </p>
   <p> something 2 </p>
   <span>         <span>  // or more html tag here
   something
</p>
something's here, not in any tag!

从:

<p class="MyClass">
   <p> something 1 </p>
   <p> something 2 </p>
   <span>         <span>  // or more html tag here
   something
</p>
something's here, not in any tag!

<p class="MyClass">
   <p> another thing 1</p>
   <p> another thing 2</p>
   <p> another thing 3</p>
   another thing
</p>
...

我想我将使用正则表达式来匹配<p class="MyClass">和下一个之间的所有内容。所以正则表达式是/(<p class="MyClass">[\s\S]*)<p class="MyClass">/,在这种情况下可以正常工作。但是当我想得到这个页面的通知时它不起作用http://daotao.dut.udn.vn/sv/G_Thongbao_LopHP.aspx。DOM 这么奇怪?!

对不起,我的英语不好。

4

1 回答 1

1

正则表达式应该是

(<p class="MyClass">[\s\S]*?)(?=<p class="MyClass">|$)
  • [\s\S]*?:*?是一个惰性量词,因此它匹配最短的默认是贪婪的(匹配最大的)。
  • (?=<p class="MyClass">|$):lookhead,使其不属于匹配项,并|$获得最后一个匹配项
于 2018-01-15T12:18:16.017 回答