Regex to get instagram picture (PHP)
<p>I'm trying to use a regular expression to check if a URL is an Instagram picture and return just the beginning part of the URL with the /p/PICTUREID</p>

<p>So far this is what I've been able to come up with:</p>

<pre><code>^(.*instagram.com\/p\/.*)\/
</code></pre>

<p>This however requires there to be a trailing slash but I do not want to require it.</p>

<p>Examples (that should match):</p>

<pre><code>https://www.instagram.com/p/BKbwlrfjGHY/?post-&gt;
https://www.instagram.com/p/BKbwlrfjGHY

http://www.instagram.com/p/BKbwlrfjGHY/ -&gt;
http://www.instagram.com/p/BKbwlrfjGHY

instagram.com/p/BKbwlrfjGHY -&gt;
instagram.com/p/BKbwlrfjGHY
</code></pre>

<p>How do I stop at the trailing slash if it exists and anything else after?</p>

<p>Here is my regex101 for testing:</p>

<p><a href="https://regex101.com/r/JJS2kz/1" rel="nofollow">https://regex101.com/r/JJS2kz/1</a></p>