【发布时间】:2018-04-21 21:13:39
【问题描述】:
<info>
<owner>
<p>Owners:</p>
<p>1. New Owner_1</p>
<p>2. New Owner_2</p>
</owner>
<addons>
<p>Name of dog: Alex</p>
<p>1. Text blah blah blah</p>
<p>2. Text blah blah blah</p>
<p>3. Text blah blah blah</p>
<p>4. Text blah blah blah</p>
<p>OR MORE Text blah blah blah</p>
</addons>
<p>DETAILS</p>
<p>1. Vicky Mears 1st dog's owner.</p>
<p>2. Paul Nash 2nd dog's owner.</p>
<p>3. Dog found last Apr. 2016</p>
</info>
您好,我目前正在为学校学习正则表达式。我的老师指出了上述结构的一个问题。
他问我们怎么找:
<p>1. ...</p>
<p>2. ...</p>
<p>3. ...</p>
但不在里面:
<p>DETAILS</p>
<p>1. Vicky Mears 1st dog's owner.</p>
<p>2. Paul Nash 2nd dog's owner.</p>
<p>3. Dog found last Apr. 2016</p>
</info>
<owner></owner>, <addons></addons> 标记在某些时候会有所不同,因此无需指定母标记,只需排除在以下位置找到的所有内容:
<p>DETAILS</p>
<p>1. Vicky Mears 1st dog's owner.</p>
<p>2. Paul Nash 2nd dog's owner.</p>
<p>3. Dog found last Apr. 2016</p>
</info>
我用这个
(?s)<p>DETAILS</p>(.*?)</info>
但它找到了我要排除的那个。
谁能帮我解决这个问题? stackoverflow 是我最后的选择。
PS:在 Notepad++ v6.8.3 中仅使用 RegEx 进行搜索
【问题讨论】:
-
@omijn我大约一周前看到了这篇文章,但据我所知对其进行了评估,发现这不是我一直在寻找的……但是,谢谢感谢您的回复。 -
到目前为止你尝试了什么?
-
@Ibrahim我使用这个(?s)<p>DETAILS</p>(.*?)</info>,但它找到了我想要排除的那个。顺便说一下,我是 RegEx 的新手。 -
请使用“编辑”将任何相关信息添加到问题中
标签: regex html-parsing regex-lookarounds regex-greedy regex-group