Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get regular expression to stop at first occurrence and then start searching from there, leading to multiple results

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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>

>Solution :

I think you’ve to make .* non greedy

use this

<h1.*?<\/h1>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading