英文:
How to get regular expression to stop at first occurrence and then start searching from there, leading to multiple results
问题
正则表达式:
<h1.*?<\/h1>
要搜索的内容:
<h1 style=""></h1><span> alsjd alkj dalsd a</span><h1>asdsadsa</h1>
结果应该是两个起始和结束h1标签的匹配项:
<h1 style=""></h1> 和
<h1>asdsadsa</h1>
英文:
I have a regular expression to search for complete h1 tags (from start of <h1>
to end of </h1>
) in a content but it searches for the whole content
Regular expression
<h1.*<\/h1>
Content to search for
<h1 style=""></h1><span> alsjd alkj dalsd a</span><h1>asdsadsa</h1>
The result is one match only from first occurrence of starting h1 to last occurrence of ending h1. It matches the whole content.
I want it to give me 2 occurrence of starting and ending h1 tags
like the result should be
<h1 style=""></h1> and
<h1>asdsadsa</h1>
答案1
得分: 1
我认为你需要将 .*
变为非贪婪模式
使用这个
<h1.*?<\/h1>
英文:
I think you've to make .*
non greedy
use this
<h1.*?<\/h1>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论