'; $regex = [ // Regex #1: Youtube '/(\s|^)(' . // Whitespace davor 'https?:\/\/(((www\.)?youtube(-nocookie)?\.com\/watch\?v=)|(youtu\.be\/))' . // Domain, Pfad '([a-zA-Z0-9_-]{8,16}' . // Video-ID '([&\?]((t=[0-9hms]{2,9})|(list=[a-zA-Z0-9_-]{16,48})))?)' . // Zeit oder Liste '([&\?][a-zA-Z0-9_=-]+)*' . // Anhängsel ')(\s|$)/' // Whitespace danach , // Regex #2: URLs '/(\s|^)(' . // Whitespace davor '((https?|ftp):\/\/)' . // Protokoll '([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+' . // Subdomains, Domain '([a-zA-Z]{2,16}\.?)' . // TLD '(\/[\x23-\x7E!äöüÄÖÜß]*)*' . // Anhängsel (Pfad, Parameter, Anker, ...) ')(\s|$)/' // Whitespace danach ]; $replace = [ // Replace #1: Youtube '$1$14' , // Replace #2: URLs '$1$2$9' ]; $html .= preg_replace( $regex, $replace, $_REQUEST['msg']); $html .= '