2012-06-08 45 views
0

我有这个URL可变图像内:url中使用Ruby的正则表达式替换字符串

image = http://graph.facebook.com/111111111111111/picture?type=square 

我想正则表达式的红宝石为等号=后替换最后一个字符串为这些网址:

image = http://graph.facebook.com/111111111111111/picture?type=small 
image = http://graph.facebook.com/111111111111111/picture?type=large 
image = http://graph.facebook.com/111111111111111/picture?type=normal 

号码111111111111111是一个15位数的号码。

我该怎么办?

非常感谢!

+2

与其向您提供解决您问题的正则表达式,请让我与您分享此链接:http://www.ruby-doc.org/core-1.9.3/Regexp.html,付费注意“重复”部分 – Anton

+0

非常感谢! – hyperrjas

回答

1
s.gsub(%r{(http://graph.facebook.com/\d{15}/picture\?type=)\w+}, '\1replaced') 
#=> "http://graph.facebook.com/111111111111111/picture?type=replaced"