jQuery从文本中提取URL [英] Jquery Extract URL from Text
本文介绍了jQuery从文本中提取URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用jquery从文本中提取URL.
I need to extract URL from a text using jquery.
让我们说我在文本区域代码后面的页面上有
Lets say i have sowhere on the page following textarea code
<textarea rows="20" name="textarea" style="width:100%;">
@techreport{blabl,
blabla = {},
url = {http://server.com/thepdf.pdf},
wrongurl ={http://server.com/thepdf2.pdf},
blablabla = 1998,
blablablabla= {blablablablabla}}
</textarea>
我只需要url内容,而不是错误的URL.
i need the url, and only the url contents - not wrongurl.
更新:它始终具有相同的结构,我只需要一次提取它,并且它前面总是有一个"url = {".
Update: it has always the same structure and i only need to extract it ONCE and it always has an "url = {" in front of it.
推荐答案
如何解决
$(document).ready(function() {
$('#click').click(function(){
var one = document.getElementById('one');
one.value.match(/url ={([^}]*)}/,"");
alert( RegExp.$1);
})
})
或可运行的演示 http://jsfiddle.net/PePS7/10/
糟糕,游戏有点晚了,但修改了示例和jsfiddle,只显示了网址
oops, bit late to the game but ammended the example and the jsfiddle to only show the url
这篇关于jQuery从文本中提取URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文