mysql - MariaDB 10.2 / MySQL 5.7 使用通配符删除字段中的文本?
问题描述
我有一个描述字段,我想删除描述中匹配的某些文本的所有出现。请注意,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/%/% ', '');
这显然不起作用。Replace 是否有任何通配符或 RegEX 功能?
解决方案
似乎您想从没有前导空格的最后一位数字开始提取摘录。所以使用:
UPDATE articles
SET description=LTRIM(
SUBSTRING( description,
- REGEXP_INSTR( REVERSE( description ) , '[0-9]' ) + 1 )
)
在哪里确定
从 -->开始 SUBSTRING()
最后 --> REVERSE()
数字 --> REGEXP_INSTR()
没有前导空格 --> LTRIM()
使用函数。
推荐阅读
- python - 代码看起来“不是pythonic” - 嵌套 np.where() 以将列添加到 pd.dataframe
- node.js - 如何在 Mac 上将 NPM 6.13.4 更新到 7.16.0?
- vue.js - 未定义带有 PixiOverlay 事件的 Vue
- java - 为什么一个 GET 请求会向 ServerSocket.accept() 发送 2 个请求?
- bash - 如何在多个文件的开头添加两行?
- c# - 我创建了一个模态组件,但它不起作用
- r - 将字符串传递给 fable 包中的函数模型
- java - RSocket-CLI:未解决的参考:clientTransport
- react-native - 放大对图像的原生反应,例如放大画廊图像,其中捏合中心的位置是恒定的
- domain-driven-design - CQRS:写模型可以消耗读模型吗?