I need a regex php code to detect links like:
t.me/joinchat/AAAAAEEYZxAYyxhdag6z6g
$String = preg_replace("/[t.me][a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/", "", $String);
preg_replace
Depending on your link structure this regex could work:
t\.me\/[-a-zA-Z0-9.]+(\/\S*)?
Demo: https://regex101.com/r/wEvuBu/1
Your regex [t.me]
is allowing a single character, with the options being t
, .
, m
, or e
. You also were missing the /
after the domain which also would have caused a failure (your alphanumerical/hyphen character class would have allowed for the domain and directories to be found if /
were added).