You are updating the audio_url regardless of one was found in the content or not.
Make it conditional:
if(preg_match_all ( "/(http|https):\/\/.*\/(.*)\.(mp3|m4a|ogg|wav|wma)/", $post->post_content, $matches )) {
update_post_meta( $post_id, 'audio_url', $matches[0][0] );
}
In this case, you could also use preg_match, because you’re only looking for a single instance.
Also make sure that your regex does work correctly. Right now, it would get you wrong results if two URLs are in the document, since “.*” is greedy and will match as much as possible. Add a ? to change that behaviour to non-greedyness. While we’re at it, let’s remove the need to escape every Slash by using different delimiters:
"!(http|https)://.*?/(.*?)\.(mp3|m4a|ogg|wav|wma)!"
You don’t really need the parentheses around that second .*?
, but maybe you have more code that needs it? Also, (http|https) could be written as https?
, the question mark makes the previous character optional.