I have an html code like below(just a part of it)
<p>
<strong>
<div align="center">
<a onclick="return hs.expand(this)" href="http://example.com/somesome.png">
<img title="some-bla-bla-text" src="http://example.com/somesome.png"
alt="some-bla-bla-text" />
</a>
</div>
</strong><br />
<strong>
<div align="center">...
and want to strip it out as
<p>
<strong>
<div align="center">
<img title="some-bla-bla-text" alt="some-bla-bla-text" />
</div>
</strong><br />
<strong>
<div align="center">...
How can I remove <a onclick="return hs.expand(this)" href="http://example.com/somesome.png"> and its closing tag </a> part of this string?
A regex to match between <a onclick="return hs.expand(this)"....> and </a> would be very helpful I think
You can probably do what you want with regexes, but you need to provide more details. Do you want to remove all anchor elements, replacing them with whatever was inside them? Or only those that contain IMG tags? Here’s a regex that peels off only those anchor tags whose first attribute is
onclick:see a demo on ideone.com
EDIT: This regex will match an anchor element with an
onclickattribute (not necessarily first).demo