Assuming I have an Amazon product URL like so
http://www.amazon.com/Kindle-Wireless-Reading-Display-Generation/dp/B0015T963C/ref=amb_link_86123711_2?pf_rd_m=ATVP
You can get the ASIN number by getting/scraping that page content and then by getting value of element by id="ASIN". It will work in all the cases and you don not need to rely on regex.