Using Perl to strip everything from a string except HTML Anchor Links

Using Perl, how can I use a regex to take a string that has random html in it with one html link with anchor, like this:

  <a href="http://example.com" target="_blank">Whatever Example</a>

and it leave ONLY that and get rid of everything else? No matter what was inside the href link with the <a, like title=, or style=, or whatever.
and it leave the anchor: “Whatever Example” and the </a>?


Source: regex

Leave a Reply