Here is my regex:
s = /(?<head>http|https):\/\/(?<host>[^\/]+)/.match("http://www.myhost.com")
How do I get the head and host groups?
Here is my regex:
s = /(?<head>http|https):\/\/(?<host>[^\/]+)/.match("http://www.myhost.com")
How do I get the head and host groups?
s['head'] => "http"
s['host'] => "www.myhost.com"
You could also use URI...
1.9.3p327 > require 'uri'
=> true
1.9.3p327 > u = URI.parse("http://www.myhost.com")
=> #<URI::HTTP:0x007f8bca2239b0 URL:http://www.myhost.com>
1.9.3p327 > u.scheme
=> "http"
1.9.3p327 > u.host
=> "www.myhost.com"
Use captures >>
string = ...
one, two, three = string.match(/pattern/).captures