如何使用 jquery regex 函数显示匹配的字符串:
var textarea = "There are two URLs: http://example1.com and http://example2.com";
var filter_url = /(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\.-=?]*)*\/?/;
if (filter_url.test(textarea)) {
$('#show_match').html('// show matched URLs //');
$('#show_match').fadeIn();
}
结果:
<div id="show_match">http://example1.com http://example2.com</div>