我想删除文章正文中包含花括号的所有段落。
例如从这一段内容:
<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 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 & 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 − = 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 − = 2 .hide-if-no-js { display: none !important; } </p>
使用以下正则表达式:<p>.*?\{.*?\}.*?</p>
由于某些奇怪的原因,它删除了整篇文章而不是这一段包含花括号的......
我对正则表达式代码做错了什么? 谢谢!
最佳答案
惰性/贪婪量词并不总是按预期工作,而是匹配不包括 <
的字符串,这对我有用:<p>[^<]*\{[^<]*</p>
关于正则表达式:删除里面有大括号的 <p></p> 段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35559031/