re = /^https:\/\/(?:www\.)?kuula.co\/share\/(?:[A-Za-z0-9]+\/)?(?:collection\/)?([A-Za-z0-9]+)(\?.*)?$/m
str = 'https://kuula.co
https://kuula.co/about
https://kuula.co/post
https://kuula.co/share
https://kuula.co/share/39u4$
https://kuula.co/post/7qQZ7
https://kuula.co/post/7qQZ7/collection/7lPZ8
http://kuula.co/share/7qQZ7
https://kuula.co/share/7qQZ7
https://kuula.co/share/collection/7lPZ8
https://kuula.co/share/7qQZ7?fs=1&abc=10
https://kuula.co/share/7qQZ7/collection/7lPZ8
https://kuula.co/share/collection/7lPZ8?vr=0
https://www.kuula.co/share/7qQZ7?abc=1
https://another-page.net/share/7qQZ7
https://kuula.co.another-page.com/share/7qQZ7'
# 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