Jayaram Jayaram - 2 months ago 20
Ruby Question

get the ASIN number from amazon URL

Given a amazon product URL, which can either be

http://amazon.com/gp/product/ASIN/*
http://amazon.com/*/dp/ASIN/*
http://amazon.com/dp/ASIN/*


how do i scrap the ASIN number from the URL in Ruby ? I am not good at writing regular expressions.

Answer

Use should find match by:

scan(/http[s]?:\/\/(?:www\.|)amazon\.com\/(?:gp\/product|[^\/]+\/dp|dp)\/([^\/]+)/)