我正在寻找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')
任何想法?谢谢
答案 0 :(得分:1)
使用以下正则表达式,并通过preg_replace
(?:https?:\/\/)?(?:www\.)?(?:my\.)?website\.com
<强>更新强>
\b(?:https?:\/\/)?(?:www\.)?[-\w]+(?:\.[-\w]+)*\.(?:com|in|tk|ir|info)\b
答案 1 :(得分:1)
你可以试试这个,我刚修改了Avinash Raj's
回答
(?:https?:\/\/)?(?:www\.)?(?:[a-z]+\.)?[a-z]+\.com