4

可能重复:
我们如何使用 MySQL 和正则表达式查找域名

我的数据库表有一个名为 url 的列,其中包含如下信息: http://xyz.com/cat/index/?page=2 http://www.google.com/webmaster.php http://yahoo.com/ dsdsd/category.aspx

我只想获取他们的域名,例如:xyz.com google.com yahoo.com

我应该如何在mysql中编写查询以获得上述结果。

请帮忙。

4

1 回答 1

8

Digital Point有人给了我答案

SELECT SUBSTRING_INDEX(REPLACE(REPLACE(url, "http://", ""), "www.", ""), '/', 1);
于 2012-09-03T16:23:00.933 回答