从字符串中删除任何类型的URL

时间:2014-10-19 07:05:12

标签: php regex

我正在寻找regex从我的字符串中删除所有类型的网址。 假设这是我想从网址清除它的字符串;

Hi , this is my website : http://my.website.com

Hi , this is my website : http://www.my.website.com

Hi , this is my website : http://www.website.com

Hi , this is my website : http://website.com

Hi , this is my website : https://website.com

Hi , this is my website : https://www.website.com

Hi , this is my website : website.com

特别是,我想正确删除('website.com')

任何想法?谢谢

2 个答案:

答案 0 :(得分:1)

使用以下正则表达式,并通过preg_replace

用空字符串替换匹配的字符串
(?:https?:\/\/)?(?:www\.)?(?:my\.)?website\.com

DEMO

PHP live

<强>更新

\b(?:https?:\/\/)?(?:www\.)?[-\w]+(?:\.[-\w]+)*\.(?:com|in|tk|ir|info)\b

DEMO

答案 1 :(得分:1)

你可以试试这个,我刚修改了Avinash Raj's回答

(?:https?:\/\/)?(?:www\.)?(?:[a-z]+\.)?[a-z]+\.com