I created a regex to replace a substring from a string. But, apparantly the regex I created is not correct. Please guide
I want to replace a regex from the Html string, but as there are multiple tags like that, it treats them as one tag, it replaces all the tags.
Method used:
pattern = <figure id="attachment_5438".*</figure>
html = html.replaceFirst(pattern, "text to replace");
Following is the Html that in which I want to replace the string
Temp
<figure id="attachment_5438" align="aligncenter" width="1832"><img ng-test class="size-full wp-image-5438" src="link/wp-content/uploads/2019/05/ATA070219portfolio_img02.jpg" alt="California red-sided garter snake (Thamnophis sirtalis infernalis) photographed at the Cheyenne Mountain Zoo in Colorado Springs, Colorado." width="1832" height="1374" /> California red-sided garter snake (<em>Thamnophis sirtalis infernalis</em>) photographed at the Cheyenne Mountain Zoo in Colorado Springs, Colorado.</figure> <figure id="attachment_5439" align="aligncenter" width="1832"><img ng-test class="size-full wp-image-5439" src="link
/wp-content/uploads/2019/05/ATA070219portfolio_img03.jpg" alt="Spanish shawl nudibranch (Flabellinopsis iodinea) photographed at the Research Experience and Education Facility, or REEF, at UC Santa Barbara in Santa Barbara, California." width="1832" height="1374" /> Spanish shawl nudibranch (<em>Flabellinopsis iodinea</em>) photographed at the Research Experience and Education Facility, or REEF, at UC Santa Barbara in Santa Barbara, California.</figure> abc
For better clarity, I nn have attached the string in the image as well