A little bit of change to the regex of the first answer and it works on all the urls I have tested.
var url = "http://www.amazon.com/Kindle-Wireless-Reading-Display-Generation/dp/B0015T963C";
m = url.match("/([a-zA-Z0-9]{10})(?:[/?]|$)");;
print(m);
if (m) {
print("ASIN=" + m[1]);
}