Back

Explore Courses Blog Tutorials Interview Questions

1 Answer

0 votes
by (44.3k points)

So normally, they would look like this and the last part of the URL is the ASIN:

http://www.amazon.com/Kindle-Wireless-Reading-Display-Generation/dp/B0015T963C

So, try this code:

var url = "http://www.amazon.com/Kindle-Wireless-Reading-Display-Generation/dp/B0015T963C";

var regex = RegExp("http://www.amazon.com/([\\w-]+/)?(dp|gp/product)/(\\w+/)?(\\w{10})");

m = url.match(regex);

if (m) { 

    alert("ASIN=" + m[4]);

}

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...