题解 | #替换链接#
替换链接
http://www.nowcoder.com/practice/4578a70b955848ff8e95c1f88c94c1ba
也就匹配了下网页正则,没啥好说。
function link() {
var reg = /(http://|https://|www.)\w+(.\w+)+(?\w+=\w+)?(#\w+)?/g;
var father = document.getElementById('jsContainer');
var content = father.innerHTML;
var str = content.replace(reg,function(item,2 == 'www.' ? `<a href = 'http://{item}:
<a href = '{item}`;
});
father.innerHTML = str;
return str;
}