Reputation: 3410
I have the following text:
<p>k</p><p><span class="placeholder" code="{YSZZ}">Samsung xyz</span> </p>
<p>khgj <span class="placeholder" code="{UIDJU}">iPhone 9k</span> </p></div>
I want to replace the span tags with their respective code attribute. For that I'm using this pattern:
/<span class="placeholder" code="(.*?)">(?:.*)<\/span>/gi
But it's matching from the first span to the last, instead of each span individually. What am I missing?
https://regex101.com/r/fP4aD7/1
Thank you
Upvotes: 0
Views: 39
Reputation: 174696
You misses a ?
. .*
is greedy by default, you need to make it as non-greedy by adding ?
next to .*
.
<span class="placeholder" code="(.*?)">.*?<\/span>
^
|
Upvotes: 2