0

I have string: Some text (some text) anylink.com www.anylink.com http://anylink.com R.I.O one-www.link.com

I have this code:

$pattern = "/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i";
$replacement = "";
$name = preg_replace($pattern, $replacement, $name);

It removes fine: anylink.com, www.anylink.com, http://anylink.com

But its also remove word R.I.O and one- how I can avoid this?

Thanks for help.

1 Answers1

0

I believe that you should be sure of what is really a link or not you need to find a pattern

I realize that all your links may end with .com so try this regex "[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+.com$"

but if you need .com.anything or .com/anything

"[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+.com.*$"
Lucas Sodré
  • 77
  • 11