Use the URI library.
def uri?(string)
uri = URI.parse(string)
%w( http https ).include?(uri.scheme)
rescue URI::BadURIError
false
rescue URI::InvalidURIError
false
end
This is a very simple example. The advantage of using the URI library over a regular expression is that you can perform complex checks.