Ruby Regular expression to match a url [duplicate]

Solution 1:

The standard URI library provides URI.regexp which is the regular expression for url string.

 require 'uri'
 string.scan(URI.regexp)

http://ruby-doc.org/stdlib/libdoc/uri/rdoc/index.html

Solution 2:

You can try this:

/https?:\/\/[\S]+/

The \S means any non-whitespace character.

(Rubular)