static public Method

URI.extract(str, schemes = nil) { |$&| ... }

Synopsis

URI::extract(str[, schemes][,&blk])

Args

str:String to extract URIs from.
schemes:Limit URI matching to a specific schemes.

Description

Extracts URIs from a string. If block given, iterates through all matched URIs. Returns nil if block given or array with matches.

Usage

require "uri"

URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.")
# => ["http://foo.example.com/bla", "mailto:test@example.com"]

Source Code

# File uri/common.rb, line 551
def self.extract(str, schemes = nil, &block)
  if block_given?
    str.scan(regexp(schemes)) { yield $& }
    nil
  else
    result = []
    str.scan(regexp(schemes)) { result.push $& }
    result
  end
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.