I’ve noticed that some of my users post YouTube links that have a trailing
#!
For example
However my current regex does not remove the #! which is causing a host of problems in the video thumbnails.
preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $url, $match);
Anyone have a suggestions on how to modify my current code to ignore the #! ?
You could just use
rtrim():