どこかで 1 行抜けているか、1 行変更する必要があると思います。さまざまな /g メソッドを試しましたが、ここで exec が私を殺していると思います。おそらく、小さな簡単な追加が欠けているか、記述方法に欠陥がある可能性があります。exec をループしているときに言及された多くのスレッドを見ましたが、置換に一致を含めているため、無限ループのように見えました。
ここに私がこれまでに得たコードがあります
var system_url="http://somesite.com/";
$('.words').mouseover(function(){
var re=new RegExp("[A-Z][A-Z][A-Z]-[0-9]{5}");
var m=re.exec($(this).html());
if (m == null) {
re=new RegExp("[0-9]{5}");
m=re.exec($(this).html());
if (m == null) {}else{
if ($(this).html().match("</a>")) {}else{
tx=$(this).html().replace(m,"<a href='"+system_url+m+"' target='_blank' title='Ticket: "+m+"'>"+m+"</a>");
$(this).html(tx);
}
}
}else{
if ($(this).html().match("</a>")) {}else{
tx=$(this).html().replace(m,"<a href='"+system_url+m+"' target='_blank' title='Ticket: "+m+"'>"+m+"</a>");
$(this).html(tx);
}
}
});
一部の HTML クラス:
<span class='words'>The quick brown ZAD-14034 jumped over the EAD-14534</span>
<span class='words'>The 13034 brown fox jumped over the ZEN-12274</span>