re = /^[^.\n]*[^\/\n]*\.\K[^\/\n]+/m
str = 'https://www.example.org/
http://example.com/
ca.gov
http://blade.example.com/bikes/airplane.php
http://alarm.example.com/
smugmug.com
shop-pro.jp
https://example.org/
qq.com
pcworld.com
symantec.com
360.cn
http://example.com/?brother=bike
http://www.example.com/behavior/bead.php
army.mil
https://example.com/boy/bedroom.php
https://example.com/
https://www.example.com/brother?activity=believe
https://www.example.net/achiever/bottle.html
http://believe.example.com/bit?bait=base&bone=ball
aboutads.info
http://www.example.com/
http://www.example.edu/afternoon
livejournal.com
http://border.example.com/box/afterthought
oaic.gov.au
https://www.example.edu/base.php
house.gov
smh.com.au
http://www.example.edu/
https://www.example.org/
lycos.com
https://border.example.com/?bridge=basket&blood=animal
hibu.com
http://example.com/'
# 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