Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 构建匹配链接的数组_Ruby On Rails_Ruby_Regex_Arrays_String - Fatal编程技术网

Ruby on rails 构建匹配链接的数组

Ruby on rails 构建匹配链接的数组,ruby-on-rails,ruby,regex,arrays,string,Ruby On Rails,Ruby,Regex,Arrays,String,我使用的是RubyonRails3.0.7,我想从一个字符串(或文本)中“删除”其中的所有链接 此时,为了匹配URL和电子邮件地址,我使用了以下正则表达式*: /((\S+)?(@|mailto\:)|((ht|f)tp(s?)\:\/\/)|([www]))\S+/ 如果我有以下字符串: 我想得到一个数组(或一些其他数据结构),填充上面字符串中存在的链接 我该怎么办? *顺便问一下:正则表达式足够好吗 可能是这样的: text = 'text here http://www.sitenam

我使用的是RubyonRails3.0.7,我想从一个字符串(或文本)中“删除”其中的所有链接

此时,为了匹配URL和电子邮件地址,我使用了以下正则表达式*:

/((\S+)?(@|mailto\:)|((ht|f)tp(s?)\:\/\/)|([www]))\S+/
如果我有以下字符串:

我想得到一个数组(或一些其他数据结构),填充上面字符串中存在的链接

我该怎么办?



*顺便问一下:正则表达式足够好吗

可能是这样的:

text = 'text here http://www.sitename.com and text here www.sitename.com and text here email@sitename.com and text here'
links = []
text.split.each do |word|
  links << word if word.match(/(((\S+)?)((@|mailto\:)|(((ht|f)tp(s?))\:\/\/)|([www]))\S+)/)
end
puts links
text='此处为文本http://www.sitename.com 和此处的文本www.sitename.com和此处的文本email@sitename.com这里是文本
链接=[]
text.split.each do|单词|

链接可能是这样的:

text = 'text here http://www.sitename.com and text here www.sitename.com and text here email@sitename.com and text here'
links = []
text.split.each do |word|
  links << word if word.match(/(((\S+)?)((@|mailto\:)|(((ht|f)tp(s?))\:\/\/)|([www]))\S+)/)
end
puts links
text='此处为文本http://www.sitename.com 和此处的文本www.sitename.com和此处的文本email@sitename.com这里是文本
链接=[]
text.split.each do|单词|
链接