0

如何匹配以下模式:

<aaa class = "dog">
   <bbb id = "one"/>
</aaa>
<aaa class = "dog">
   <bbb id = "two"/>
</aaa>
<aaa class = "dog">
   <bbb id = "three"/>
</aaa>

我想:

<aaa class = "dog">
   <bbb id = "three"/>
</aaa>

我用:

^(.)*dog(.|\r|\n|\t)*(three)

但它匹配:

<aaa class = "dog">
   <bbb id = "one"/>
</aaa>
<aaa class = "dog">
   <bbb id = "two"/>
</aaa>
<aaa class = "dog">
   <bbb id = "three

我应该如何编辑正则表达式以匹配我想要的?

4

1 回答 1

1

如果要匹配提到的确切三行,可以使用以下正则表达式:

<aaa class = "dog">[\r\n\t\s]*<bbb id = "three"/>[\r\n\t\s]*</aaa>
于 2013-01-30T07:52:33.377 回答