如何使用正则表达式提取所需信息?

t122 2008-05-29 04:43:44
数据库中数据如下:
字段:referer
https://forum.csdn.net/PointForum/Forum/PostTopic.aspx?forumID=6e0e6207-de3a-4c0b-8f8a-052fcba6392a
http://csdn.net/PointForum/Forum/PostTopic.aspx?forumID=6e0e6207-de3a-4c0b-8f8a-052fcba6392a
如何实现如下结果
csdn.net
csdn.net

...全文
132 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
t122 2008-06-04
  • 打赏
  • 举报
回复
楼上的,数据库里也可以有这样一条记录,如下
https://www.cmbchina.com
要求结果如下
cmbchina.com
hery2002 2008-05-30
  • 打赏
  • 举报
回复
declare @tb table (id int identity(1,1), url nvarchar(100))
insert into @tb
select 'https://forum.csdn.net/PointForum/Forum/PostTopic.aspx?forumID=6e0e6207-de3a-4c0b-8f8a-052fcba6392a'
union all select 'http://csdn.net/PointForum/Forum/PostTopic.aspx?forumID=6e0e6207-de3a-4c0b-8f8a-052fcba6392a'
union all select 'http://sports.sina.com.cn/'

select --substring(url,7,charindex('/',substring(url,7,len(url))-1)
substring(url,8,len(url)),
substring(url,8,charindex('/',substring(url,8,len(url)))-1),
parsename( substring(url,8,charindex('/',substring(url,8,len(url)))-1),4),
parsename( substring(url,8,charindex('/',substring(url,8,len(url)))-1),3),
parsename( substring(url,8,charindex('/',substring(url,8,len(url)))-1),2),
parsename( substring(url,8,charindex('/',substring(url,8,len(url)))-1),1)

from @tb
---------------------------------------------------------------------------------------------------- ------------------- --------- ------- ------------ ------
forum.csdn.net/PointForum/Forum/PostTopic.aspx?forumID=6e0e6207-de3a-4c0b-8f8a-052fcba6392a forum.csdn.net NULL forum csdn net
csdn.net/PointForum/Forum/PostTopic.aspx?forumID=6e0e6207-de3a-4c0b-8f8a-052fcba6392a csdn.net NULL NULL csdn net
sports.sina.com.cn/ sports.sina.com.cn sports sina com cn

(3 row(s) affected)


t122 2008-05-30
  • 打赏
  • 举报
回复
不好意思,忘记说了,数据库也可以是这样
https://forum.csdn.net/PointForum/Forum/PostTopic.aspx?forumID=6e0e6207-de3a-4c0b-8f8a-052fcba6392a
http://csdn.net/PointForum/Forum/PostTopic.aspx?forumID=6e0e6207-de3a-4c0b-8f8a-052fcba6392a
http://sports.sina.com.cn/
......
结果如下
csdn.net
csdn.net
sina.com.cn
......
elvis_gao 2008-05-29
  • 打赏
  • 举报
回复
大家踊跃答问题,我是帮楼主顶贴的
arrow_gx 2008-05-29
  • 打赏
  • 举报
回复
csdn.net
csdn.net

?? 这个是确定的 ? 那根本不需要正则表达式的啊

select 'csdn.net' as referer from table

22,294

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧