Embedding Audiomack Player onto website using php

I use the following preg match

if (preg_match('![?&]{1}v=([^&]+)!', 'youtubeurl' . '&', $m)) $video_id = $m[1];

to get the youtube V value, store it in $video_id which I then add to an iframe;

<iframe width="100%" height="305" src="http://www.youtube.com/embed/<? echo $video_id; ?>?rel=2&autoplay=0" frameborder="0" allowfullscreen></iframe>

to load a youtube video on my website. Am trying to use the same approach for Audiomack but their URL format is different.

Audiomack uses the following URL format;

https://www.audiomack.com/song/famous-dex/annoyed

And their iframe is as follows;

<iframe src="https://www.audiomack.com/embed/song/famous-dex/annoyed" scrolling="no" width="100%" height="110" scrollbars="no" frameborder="0"></iframe>

How can I modify the above preg_match to obtain the last two strings from the URL together with the slash, store it in a variable and then call it from an iframe?

eg.

$url = 'https://www.audiomack.com/famous-dex/song/annoyed';    
if (preg_match('![?&]{1}v=([^&]+)!', '$url' . '&', $m)) $audio_id = $m[1];

and the value of $audio_id should return song/famous-dex/annoyed then I can insert it into the iframe as such;

<iframe src="https://www.audiomack.com/embed/<? echo $audio_id; ?>" scrolling="no" width="100%" height="110" scrollbars="no" frameborder="0"></iframe>

Use this code:

$url = 'https://www.audiomack.com/embed4/famous-dex/annoyed';
if (preg_match('/.+\/(.+\/.+)$/', $url, $matches)) {
    $audio_id = $matches[1];
    echo $audio_id; // gives you famous-dex/annoyed
}
  1. Match anything else till you reach the "/"
  2. Capture any two characters, words, etc which are separated by a "/"
  3. End the match search.

Without the "$" the search will fail, since in this context it is kind of forcing the search to "start from the end, backwards".