我有一个输入字段,用户可以发布到Facebook页面的链接。现在我正在使用正则表达式来验证URL。如何替换部分输入值?
URL_regex = /\A(http|https|ftp):\/\/([\w]*)\.([\w]*)\.(com|net|org|biz|info|mobi|us|cc|bz|tv|ws|name|co|me)(\.[a-z]{1,3})?/i
我只想以下四个版本通过验证:
https://www.facebook.com/redbull
http://www.facebook.com/redbull
www.facebook.com/redbull
facebook.com/redbull
ŧ母鸡我想只想在数据库中存储“redbull”部分。我试过Rubular,但我无法弄清楚正则表达式的逻辑。
在此先感谢
找到了解决方案,THX到凯莱:
URL_regex = /\A((http|https):\/\/)?(www\.)?facebook\.com\/([\S]+)/i
thx,很棒! – 2011-05-04 10:10:35