0
var LinkString="Google Link Is:<a href='www.Google.com' target='_blank' style='text-decoration:none; color:#000000;'>URL</a>";

I want to extract full anchor tag from LinkString.

Tushar
  • 85,780
  • 21
  • 159
  • 179
jayesh patil
  • 63
  • 14

2 Answers2

1

try this

    var LinkString="Google Link Is:<a href='www.Google.com' target='_blank' style='text-decoration:none; color:#000000;'>URL</a>";
    var output = LinkString.split(/(?=<a)/)[1];
    alert(output);

Or

var LinkString="Google Link Is:<a href='www.Google.com' target='_blank' style='text-decoration:none; color:#000000;'>URL</a>";
alert(LinkString.match(/(?=<a)[\w\W]+a>/));

Or if you are sure that there will always be only one anchor tag in this string then simply

    var LinkString="Google Link Is:<a href='www.Google.com' target='_blank' style='text-decoration:none; color:#000000;'>URL</a>";
    var output = LinkString.substring( LinkString.indexOf("<a"),  LinkString.indexOf("</a>")+4);
    alert(output);
gurvinder372
  • 66,980
  • 10
  • 72
  • 94
1

Try this it will work :

Split the LinkString using javascript split() function. It return you an array of values seperated by :.

var LinkString="Google Link Is:<a href='www.Google.com' target='_blank' style='text-decoration:none; color:#000000;'>URL</a>";
    var output = LinkString.split(':');
    console.log(output[1] + output[2] + output[3]);

JSFiddle Demo : https://jsfiddle.net/uxwz3o1k/

=============================== OR ========================================

var LinkString="Google Link Is:<a href='www.Google.com' target='_blank' style='text-decoration:none; color:#000000;'>URL</a>";
    var output = LinkString.split(/(?=<a)/);
    console.log(output[1]);

JSFiddle Demo : https://jsfiddle.net/uxwz3o1k/1

===============================OR=========================================

var LinkString="Google Link Is:<a href='www.Google.com' target='_blank' style='text-decoration:none; color:#000000;'>URL</a>";
    var indexOpenAnchor = LinkString.indexOf('<a');
     var indexClosingAnchor = LinkString.indexOf('a>');
    console.log(LinkString.substring(indexOpenAnchor,indexClosingAnchor+2));

JSFiddle Demo : https://jsfiddle.net/uxwz3o1k/2/

Debug Diva
  • 26,058
  • 13
  • 70
  • 123