re = /(?:\/p\/|$)(?:[^\/]*)(?<=-)(.*)(?=\/)/
str = 'https://www.ikea.com/de/de/p/hallbar-abfalltrennungsloesung-mit-auszug-hellgrau-s09308825/
https://www.ikea.com/de/de/p/symfonisk-regal-wifi-speaker-schwarz-50357554/?tduid=d8b332c221610a36288c647f8959959f&utm_medium=affiliate&utm_name=generic&utm_term=conversion&utm_content=deeplink&utm_source=SmartApfel
https://www.ikea.com/de/de/p/symfonisk-tischleuchte-mit-wifi-speaker-weiss-30435157/?tduid=d8b332c221610a36288c647f8959959f&utm_medium=affiliate&utm_name=generic&utm_term=conversion&utm_content=deeplink&utm_source=SmartApfel
https://www.ikea.com/de/de/p/tradfri-gateway-weiss-40337806/?tduid=d8b332c221610a36288c647f8959959f&utm_content=feed&utm_medium=affiliate&utm_name=generic&utm_source=SmartApfel&utm_term=conversion
https://www.ikea.com/de/de/p/fyrtur-verdunklungsrollo-kabellos-batteriebetrieben-grau-40408196/?tduid=d8b332c221610a36288c647f8959959f&utm_content=feed&utm_medium=affiliate&utm_name=generic&utm_source=SmartApfel&utm_term=conversion
https://www.ikea.com/de/de/p/kadrilj-rollo-kabellos-batteriebetrieben-grau-90408127/?tduid=d8b332c221610a36288c647f8959959f&utm_content=feed&utm_medium=affiliate&utm_name=generic&utm_source=SmartApfel&utm_term=conversion'
# 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