It will work for you
\S*\bwww\.youtube\.com\S*
\S* matches zero or more characters without a space.
The code will be
preg_match('~\S*\bwww\.youtube\.com\S*~', $str, $matches);
Demo
And I made some corrections to the original regex.
(?:https?://)?(?:www.)?(?:youtube.com|youtu.be)/(?:watch\?v=)?([^\s]+)
Demo
$str = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, https://www.youtube.com/watch?v=7TL02DA5MZM when an unknown printer took a galley of type and scrambled it to make a type"; preg_match('~(?:https?://)?(?:www.)?(?:youtube.com|youtu.be)/(?:watch\?v=)?([^\s]+)~', $str, $match); print_r($match);
Conclusion:
Array ( [0] => https:
source share