re = /([^\/]+)\/?
/m
str = 'https://www.ducati.com/es/es/motocicletas/monster/monster-797
https://www.ducati.com/es/es/motocicletas/diavel/diavel-1260
https://www.ducati.com/es/es/motocicletas/hypermotard/hypermotard
https://www.ducati.com/es/es/motocicletas/hypermotard/hypermotard-950
https://www.ducati.com/es/es/motocicletas/monster/monster-1200
https://www.ducati.com/es/es/motocicletas/monster/monster-1200-25-anniversario
https://www.ducati.com/es/es/motocicletas/monster/monster-1200r
https://www.ducati.com/es/es/motocicletas/monster/monster-797
https://www.ducati.com/es/es/motocicletas/monster/monster-821
https://www.ducati.com/es/es/motocicletas/multistrada/multistrada-1260
https://www.ducati.com/es/es/motocicletas/multistrada/multistrada-1260-enduro
https://www.ducati.com/es/es/motocicletas/multistrada/multistrada-950
https://www.ducati.com/es/es/motocicletas/multistrada/multistrada-enduro
https://www.ducati.com/es/es/motocicletas/panigale/1299-panigale-r-final-edition
https://www.ducati.com/es/es/motocicletas/panigale/959-panigale
https://www.ducati.com/es/es/motocicletas/panigale/panigale-v4
https://www.ducati.com/es/es/motocicletas/panigale/panigale-v4-r
https://www.ducati.com/es/es/motocicletas/supersport/supersport
https://www.ducati.com/es/es/motocicletas/xdiavel/xdiavel
'
# 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