user3674148 user3674148 - 1 year ago 92
Javascript Question

Split string on <a> tag

I would like to split the below value:

var stringValue = "<a href="/DE/Company/OurOrganisation/ActionsDE.pdf">DE</a><a href="/EN/Company/OurOrganisation/Act‌​ionsEN.pdf">EN</a><a href="/FR/Company/OurOrganisation/Act‌​ionsFR.pdf">FR</a>";

As we see, there are 3 anchors hence I have tried

1. var result = stringValue.split("<a/>");

2. var myRegexp = new RegExp("<a/>");
var result = stringValue.split(myRegexp);

What would be the best regex or way to get these 3 anchors ?

Answer Source

here's a pure regex solution:

var stringValue = '<a href="/DE/Company/OurOrganisation/ActionsDE.pdf">DE</a><a href="/EN/Company/OurOrganisation/Act‌ionsEN.pdf">EN</a><a href="/FR/Company/OurOrganisation/Act‌ionsFR.pdf">FR</a>';

var ar = stringValue.match(/<a.*?<\/a>/g)


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download