从字符串中提取URL?

时间:2013-01-14 09:21:39

标签: ruby

  

可能重复:
  Extract Url From a String

我有一个字符串:

abchghhdgfdgfdfdfhttp://www.rajasthanpatrika.com/News/World/1132013/international news/414309\r\n\t\t\t\t     ghjghjfhjvfhjhfj"

我想提取网址:

http://www.rajasthanpatrika.com/News/World/1132013/international news/414309

我该怎么做?

1 个答案:

答案 0 :(得分:1)

s = "abchghhdgfdgfdfdfhttp://www.rajasthanpatrika.com/News/World/1132013/international news/414309\r\n\t\t\t\t ghjghjfhjvfhjhfj"
s[/http:\/\/.*?(?=[\r\n\t])/]
# => "http://www.rajasthanpatrika.com/News/World/1132013/international news/414309"