Jquery 从文本中提取 URL
我需要使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
怎么样
这个或可运行的演示
http://jsfiddle.net/PePS7/10/
哎呀,游戏有点晚了,但修改了示例和 jsfiddle 仅显示 url
how about this
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
你需要对此进行一些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.
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]
最简单的方法是使用正则表达式,就像每个人都指出的那样。
该正则表达式应该可以做到。
The easiest thing to do is to use a regexp, like everyone has pointed to.
That regexp should do it.