MariaDB 10.2 / MySQL 5.7使用通配符删除字段中的文本吗?

问题描述 投票:0回答:2

我有一个描述字段,我想删除所有在描述中匹配的文本。请注意,81/29将始终是不同的数字。有时它们的位数可能更多,例如2-4位。

样本数据:

To support this group, visit: https://example.com/give/81/29 The normal description continues here. There will be a lot of text below....

查询后:

The normal description continues here. There will be a lot of text below.... 

是否有搜索和替换通配符的方法?

例如:

UPDATE articles 
SET description = REPLACE(description, 'To support this group, visit: https://example.com/give/%/% ', '');

这显然不起作用。替换是否具有任何通配符或RegEX函数?

mysql sql replace mariadb wildcard
2个回答
0
投票

[使用字符串函数LOCATE()INSTR()

UPDATE articles 
SET description = SUBSTRING(
  description, 
  LOCATE(' ', description, INSTR(description, 'https')) + 1
);

请参见demo


0
投票

似乎您要提取摘录从...开始 没有前导空格的最后一位数字。所以使用:

UPDATE articles 
   SET description=LTRIM(
                         SUBSTRING( description, 
                                  - REGEXP_INSTR( REVERSE( description ) , '[0-9]' ) + 1 )
                   )  

确定地点

从...开始 -> SUBSTRING()

last -> REVERSE()

数字 -> REGEXP_INSTR()

没有前导空格 -> LTRIM()

使用功能。

Demo

© www.soinside.com 2019 - 2024. All rights reserved.