Reputation: 63
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.
Upvotes: 0
Views: 97
Reputation: 27202
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/
Upvotes: 1
Reputation: 68393
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);
Upvotes: 1