$re = '~^.*?(\bhttps?://\S+\b)\V*~ms';
$str = 'Using the text from this reddit post:
https://www.reddit.com/r/AfterEffects/comments/swn8zt/some_lesser_known_ae_youtube_channels_to_check_out/
I just wanted to bring some attention to some of the \'lesser known\' After Effects tutorial channels which have great content and deserve more of a following, check them out! :)
Michael Ponch: https://www.youtube.com/c/MichaelPonch if there is text at the end of the line it doesn\'t know how to handle it
edwin rowin: https://www.youtube.com/c/edwinrowin
Chunk: https://www.youtube.com/c/ChunkMotion
Mackesomething: https://www.youtube.com/c/Mackesomething
NT Productions: https://www.youtube.com/c/NTProductions
Motion Designer: https://www.youtube.com/c/MotionDesigner
LunarStudios: https://www.youtube.com/c/LunarStudiosOfficial
NoSleepCreative: https://www.youtube.com/c/NoSleepCreative
Regulus: https://www.youtube.com/c/georegulus
Francisco Giordano: https://www.youtube.com/channel/UCdq-YsmUOpWIgVnYejrmG7Q';
$subst = "$1";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php