mySQL:删除正则表达式子字符串

标签 mysql regex string

我的 url 以下列格式存储在我的数据库表中

http://domain.com/images/4/8/48bafb746bb7baa695481574afc345eb61af8d0a.jpg,和http://domain.com/images/0/f/0f602869e208139d2da67867359fb7cf092eb02b.jpg。 jpg

我想更改文件存储的目录并在数据库中反射(reflect)此更改。类似于以下内容。

http://domain.com/images/48bafb746bb7baa695481574afc345eb61af8d0a.jpg,以及http://domain.com/images/0f602869e208139d2da67867359fb7cf092eb02b.jpg.jpg

我只是想将所有图像向上移动两个目录。如何从字符串中删除前两个目录?

最佳答案

尝试使用 substring_index

 select concat('http://domain.com/images/', substring_index('http://domain.com/images/4/8/48bafb746bb7baa695481574afc345eb61af8d0a.jpg','/',-1))

要编辑您的记录,您可以这样做:

 update yourtable set yourcoulmnpath= concat('http://domain.com/images/', substring_index(yourcoulmnpath,'/',-1))

关于mySQL:删除正则表达式子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23999373/

相关文章:

php - 如何连接到另一台服务器上的数据库

php - 如何在 PHP 5.5 中使用 password_needs_rehash 函数

regex - Sinatra 路由正则表达式字母数字

regex - 在 Visual Studio Code 中全局查找并替换为换行符

正则表达式在 R 中的逗号之前或之后提取数据

string - 查找可能的字符串变体数量的算法

php - 交换 SQL 主键而不影响自增?

mysql - 车库里有多少辆车?在两个表中选择(Mysql)

c - 从c中的字符串中删除标点符号和空格?

Javascript 用 <NewWord> 替换字符串返回空