title: Where can I get the instagram shortcode from this url
body: <p>I have been using the Instagram API for some time, but I see a certain url that is causing me problems. So far, I have been pulling the shortcode from a url like so:</p>
  
  <pre><code>const instagramRegex = /https:\/\/www.instagram.com\/p\/([\w-]+)\/?/g;
  let shortcode = instaRegex.exec(url)[1];
  </code></pre>
  
  <p>This returns the shortcode as expected, something that looks like BU89NChA8Cz from a url like <a href="https://www.instagram.com/p/BU89NChA8Cz/" rel="nofollow noreferrer">https://www.instagram.com/p/BU89NChA8Cz/</a>. The problem now is, the following url returns html, not a json response as expected. It is also not likely a shortcode.</p>
  
  <p><strong>Problem url:</strong> <a href="https://www.instagram.com/p/BTC-qwADp7WmlJ06W_Z_B59Bxbpml31t_fb-3U0/" rel="nofollow noreferrer">https://www.instagram.com/p/BTC-qwADp7WmlJ06W_Z_B59Bxbpml31t_fb-3U0/</a></p>
  
  <p>The regex still returns the "shortcode" as expected: BTC-qwADp7WmlJ06W_Z_B59Bxbpml31t_fb-3U0, but this is not what I want as it is a "Page Not Found" HTML doc, not an api response.</p>
  
  <p>I have also tried variations of this larger code, splitting on "_", but each of those returns "invalid media id"</p>
  
  <p>What am I doing wrong?</p>