title: Extract Amzon ASIN from URL, RE, python
body: <p>I have a huge list of urls with links to Amazon products, this urls have an information contained within that I need that is called ASIN number.</p>
  
  <p>I understand that one of the best ways to extract that information is via <strong>Regular Expressions</strong>, I found a pattern in the urls that could help</p>
  
  <p>1- <a href="https://rads.stackoverflow.com/amzn/click/com/B07P4LVZNL" rel="nofollow noreferrer" rel="nofollow noreferrer">https://www.amazon.com/adidas-Melange-Performance-T-Shirt-Charcoal/dp/B07P4LVZNL/ref=sr_1_fkmr1_2?dchild=1&amp;keywords=Adidas+M%C3%A8lange+Tech+T-Shirt+A372&amp;qid=1579685244&amp;sr=8-2-fkmr1</a></p>
  
  <p>2- <a href="https://rads.stackoverflow.com/amzn/click/com/B07DXPN7TK" rel="nofollow noreferrer" rel="nofollow noreferrer">https://www.amazon.com/adidas-Originals-Solid-Melange-Purple/dp/B07DXPN7TK/ref=sr_1_fkmr2_1?dchild=1&amp;keywords=Adidas+M%C3%A8lange+Tech+T-Shirt+A372&amp;qid=1579685244&amp;sr=8-1-fkmr2</a></p>
  
  <p>3- <a href="https://www.amazon.com/adidas-Game-Mode-Polo-Multi-Sport/gp/B07R23QGH6/ref=sr_1_fkmr2_2?dchild=1&amp;keywords=Adidas+M%C3%A8lange+Tech+T-Shirt+A372&amp;qid=1579685244&amp;sr=8-2-fkmr2" rel="nofollow noreferrer">https://www.amazon.com/adidas-Game-Mode-Polo-Multi-Sport/gp/B07R23QGH6/ref=sr_1_fkmr2_2?dchild=1&amp;keywords=Adidas+M%C3%A8lange+Tech+T-Shirt+A372&amp;qid=1579685244&amp;sr=8-2-fkmr2</a></p>
  
  <p>The respective ASIN numbers are:</p>
  
  <p>1- <strong>B07P4LVZNL</strong>, located between: <strong>dp/B07P4LVZNL/ref=sr_1_f</strong></p>
  
  <p>2- <strong>B07DXPN7TK</strong>, located between: <strong>dp/B07DXPN7TK/ref=sr_1_fkmr2_</strong></p>
  
  <p>3- <strong>B07R23QGH6</strong>, located between: <strong>gp/B07R23QGH6/ref=sr_1_fkmr2_</strong></p>
  
  <p>I tried this code:</p>
  
  <pre><code>asin = re.match("http[s]?://www.amazon.com(\w+)(.*)/(dp|gp/product)/(?P&lt;asin&gt;\w+).*", href, flags=re.IGNORECASE)
  </code></pre>
  
  <p>href is the variable where I have stored the urls </p>
  
  <p>But well... It doesn't work quite well, this is the type of result I get:</p>
  
  <pre><code>&lt;re.Match object; span=(0, 175), match='https://www.amazon.com/adidas-Originals-Solid-Mel&gt;
  &lt;re.Match object; span=(0, 171), match='https://www.amazon.com/adidas-Game-Mode-Polo-Mult&gt;
  &lt;re.Match object; span=(0, 167), match='https://www.amazon.com/adidas-Tech-Tee-Black-X-La&gt;
  </code></pre>
  
  <p><strong>Thank you for your help</strong></p>