Method: URI.regexp

Defined in:
lib/uri/common.rb

.regexp(schemes = nil) ⇒ Object

Synopsis

URI::regexp([match_schemes])

Args

match_schemes

Array of schemes. If given, resulting regexp matches to URIs whose scheme is one of the match_schemes.

Description

Returns a Regexp object which matches to URI-like strings. The Regexp object returned by this method includes arbitrary number of capture group (parentheses). Never rely on it’s number.

Usage

require 'uri'

# extract first URI from html_string
html_string.slice(URI.regexp)

# remove ftp URIs
html_string.sub(URI.regexp(['ftp'])

# You should not rely on the number of parentheses
html_string.scan(URI.regexp) do |*matches|
  p $&
end


327
328
329
330
# File 'lib/uri/common.rb', line 327

def self.regexp(schemes = nil)
  warn "#{caller(1)[0]}: warning: URI.regexp is obsolete" if $VERBOSE
  DEFAULT_PARSER.make_regexp(schemes)
end