$re = '/(t(?:elegram)?\.(?:org|me|dog))\/(?:(joinchat\/[a-zA-Z0-9\-_]{22})|([a-zA-Z0-9\-_]+))/m';
$str = 't.me/somechat
t.me/joinchat/fdffdddddddddddddd
t.me/joinchat/A7LmgRHHG0IGxhE71LbfoA
t.me/sdsds/sds/dsd/sd
telegram.me/joinchat/A7LmgRHHG0IGxhE71LbfoA
t.me/c/1478172822/10716
https://t.me/botspamdebug/20573
https://t.me/joinchat/NEChjFgbIJYHp15Oyr8g-w';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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