pocek pocek - 4 years ago 136
PHP Question

php regex for t.me links

I need a regex php code to detect links like:


I've tried :

$String = preg_replace("/[t.me][a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/", "", $String);

I need to use
but the code above not working :(

What should i do with this?

Answer Source

Depending on your link structure this regex could work:


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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download