嗨,我需要从纯文本 url 检测和转换 url 图像和视频
html
<div id="content-url">
Hello World<br>
http://www.goalterest.com/ <br>
http://www.esotech.org/wp-content/uploads/2011/12/jquery_logo.png
http://www.esotech.org/wp-content/uploads
</div>
jQuery
var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
var photoRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]).(?:jpg|gif|png)/ig;
var url_url= $('#content-url').html().match(urlRegex);
var url_photo= $('#content-url').html().match(photoRegex);
var convert_url='<a href="'+url_url+'">'+url_url+'</a>';
var convert_photo='<img src="'+url_photo+'" width="150" height="150" alt="Nba">';
$('#content-url').append(convert_url);
$('#content-url').append(convert_photo);
这里演示 http://jsfiddle.net/nqVJc/3/
在演示中,我得到了检测并转换为 url 和照片的方法,但是当存在多个 url 时,问题就出现了 Urls 没有分开