0

可能重复:
从字符串中提取 URL

我有一个像这样的字符串:

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

我怎样才能做到这一点?

4

1 回答 1

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"
于 2013-01-14T11:08:42.647 回答