正则表达式:删除里面有大括号的 <p></p> 段落

标签 regex brackets braces

我想删除文章正文中包含花括号的所有段落。

例如从这一段内容:

<p>While orthotic inserts are able to provide great support and pain relief, they aren’t quite as good as a specialty shoe. Remember that an ill-fitting insert can cause permanent damage and talk to a podiatrist about your foot pain for the best recommendation. Click here&nbsp;if you want to learn more about pain in the foot arch unrelated to plantar fasciitis.</p> <h2>Related Posts</h2> <h2>So What Are These Socks Really Good For?</h2> <h2>Are the bottom of your feet causing you problems?</h2> <h2>A PF Relief Guide</h2> <h2>What is Foot Reflexology &amp; What is it Good For?</h2> <h2>Leave a Reply Cancel reply</h2> <p>Your email address will not be published. Required fields are marked *</p> <p>Name</p> <p>Email</p> <p>Website</p> <p>five &nbsp;−&nbsp; &nbsp;=&nbsp; 2 .hide-if-no-js { display: none !important; } </p><h2>Food For Thought January 2016</h2> <h2>Show Us Some Social Love!!</h2> <h2>Recent Posts</h2> <li> The Climate Pledge of Resistance</li> <li> Green Activism in Boulder, Colorado</li> <li> The Truth About Money and Happiness</li> <li> Why Is There So Much Skepticism About Climate Change?</li> <li> Which Device Would Work Best For You?</li>

我想删除这部分:

<p>five &nbsp;−&nbsp; &nbsp;=&nbsp; 2 .hide-if-no-js { display: none !important; } </p>

使用以下正则表达式:<p>.*?\{.*?\}.*?</p>

由于某些奇怪的原因,它删除了整篇文章而不是这一段包含花括号的......

我对正则表达式代码做错了什么? 谢谢!

最佳答案

惰性/贪婪量词并不总是按预期工作,而是匹配不包括 < 的字符串,这对我有用:<p>[^<]*\{[^<]*</p>

关于正则表达式:删除里面有大括号的 <p></p> 段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35559031/

相关文章:

javascript - 带方括号的 Node.js 全局变量和函数 - 为什么这有效?

c - 递归解析 - 括号

python - PyParsing 解析带有大括号和特定 header 的嵌套循环

c++ - while 循环中的 if/else 格式

java - 使用分隔符进行标记

javascript - 验证文件时在正则表达式中允许空格

python - 正则表达式 - 删除分隔符之间的字符串

javascript - 正则表达式查找所有出现的字符串然后找到它之后的下一个空格

vim - 在 ViM 中禁用突出显示匹配的括号 : "let loaded_matchparen = 1" not working

javascript - ES6 JavaScript 中的括号