Jquery 从文本中提取 URL

发布于 2024-10-02 18:54:38 字数 455 浏览 0 评论 0原文

我需要使用 jquery 从文本中提取 URL。

可以说,我在文本区域代码后面的页面上的某个地方

<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 内容 - 而不是错误的 url。

更新:它始终具有相同的结构,我只需要提取它一次,并且它前面总是有一个“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>

i need the url, and only the url contents - not wrongurl.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

独木成林 2024-10-09 18:54:38

怎么样

$(document).ready(function() {

    $('#click').click(function(){

 var one = document.getElementById('one');       
    one.value.match(/url ={([^}]*)}/,"");
    alert( RegExp.$1);


    })    
})

这个或可运行的演示
http://jsfiddle.net/PePS7/10/

哎呀,游戏有点晚了,但修改了示例和 jsfiddle 仅显示 url

how about this

$(document).ready(function() {

    $('#click').click(function(){

 var one = document.getElementById('one');       
    one.value.match(/url ={([^}]*)}/,"");
    alert( RegExp.$1);


    })    
})

or a runnable demo
http://jsfiddle.net/PePS7/10/

oops, bit late to the game but ammended the example and the jsfiddle to only show the url

帅气尐潴 2024-10-09 18:54:38

你需要对此进行一些Reg ex处理。如果我更擅长这些,我会为你写一篇。

You're going to need to do some Reg ex on this. If I was better at them I'd write one up for you.

一个人练习一个人 2024-10-09 18:54:38

jQuery 不会这样做,您正在寻找一个正则表达式来从此文本区域中的“url”属性中提取 URL。您可以使用以下正则表达式来执行此操作:

/url = \{(.+)\}/.exec(textarea_str)[1]

jQuery won't do this, you're looking for a regular expression to extract the URL from the 'url' property in this textarea. You can do this with the following regex:

/url = \{(.+)\}/.exec(textarea_str)[1]

叹梦 2024-10-09 18:54:38

最简单的方法是使用正则表达式,就像每个人都指出的那样。

/url = \{([^}]*)\}/

该正则表达式应该可以做到。

The easiest thing to do is to use a regexp, like everyone has pointed to.

/url = \{([^}]*)\}/

That regexp should do it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文