You should not try to process HTML with regex, as there are too many things that could go wrong. In this case, what if you have the tag as <A HREF...>
? Or what about other tags that start with a
such as <area>
, <abbr>
, <acronym>
and so on? What if there's already a target
attribute?
Instead, try treating the HTML as HTML and not as plain text. You have an engire engine at your fingertips.
var tmp = document.createElement('div');
tmp.innerHTML = itemdescription;
var links = tmp.getElementsByTagName('a'), l = links.length, i;
for( i=0; i<l; i++) {
links[i].setAttribute("target","_blank");
}
editdescription = tmp.innerHTML;