re = /http:\/\/(?<domain>[^\/\n]+)\/[^\?\n]+[?](?<params>[^\n]+)/
str = 'http://site.com/index.php?id=1
http://site.com/index.php?id=2
http://site.com/index.php?id=3
http://site.com/index.php?id=1¶m=a
http://site.com/index.php?id=1¶m=b&year=2015
http://site2.com/index.php?id=3
http://site2.com/index.php?id=4
http://site2.com/index.php?id=5
http://site2.com/index.php?id=1¶m=x
http://site2.com/index.php?id=1¶m=y
http://site2.com/index.php?id=3¶m=z'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html