gpt4 book ai didi

mysql - 从文本字符串中删除网址

转载 作者:行者123 更新时间:2023-11-29 01:57:55 25 4
gpt4 key购买 nike

这是“能否完成”问题之一。我有一个同事来找我从数据库文本字符串中删除网址——除了以 http 开头外,所有网址都是唯一的。我的第一直觉是使用替换功能,但使用和维护起来会变得非常麻烦。

所以我在论坛上询问他们对如何最好地完成这项任务的想法。

 This is a test http://t.co/aBc689XYz -> new result=This is a test
Have a nice http://t.co/vZ754PlkuI day -> new result=Have a nice day

最佳答案

如果 URL 部分在文本中只存在一次,则以下内容应该有效。

MySQL 解决方案:

select concat( @pss:=substring_index( txt, 'http://', 1 ), 
substring( @ss:=substring_index( txt, 'http://', -1 ),
if( (@l:=locate( ' ', @ss )) > 0, @l+1, 0 ) )
) as txt
from (
select 'This is a test http://t.co/aBc689XYz' as txt
union all
select 'Have a nice http://t.co/vZ754PlkuI day'
union all
select 'This worked http://sqlfiddle.com/#!2/d41d8 perfectly on sql fiddle'
) records
;

结果:

+-------------------------------------+
| txt |
+-------------------------------------+
| This is a test |
| Have a nice day |
| This worked perfectly on sql fiddle |
+-------------------------------------+

演示 @ MySQL 5.5.32 Fiddle

关于mysql - 从文本字符串中删除网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23251506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com