MySQL 用正则表达式更新mysql

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10465288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:15:47  来源:igfitidea点击:

mysql update with regexp

mysqlregex

提问by cj333

I want to remove something from my table 1)32)121)1000)... the format is number+ )

我想从我的表中删除一些东西1)32)121)1000)...格式是number+)

I tried this code.

我试过这个代码。

UPDATE articles SET 
title= REPLACE(title,'\d)', '' ) 
WHERE title regexp "\d)*"

Nothing happened in phpmyadmin, how to write correct? Thanks.

什么都没发生phpmyadmin,怎么写正确?谢谢。

采纳答案by Bohemian

You can't: Mysql doesn't support regex-based replace.

你不能:Mysql 不支持基于正则表达式的替换。

See this SO questionfor a work-around.

有关解决方法,请参阅此 SO 问题

回答by cj333

Finally, I use some php to solve this problem with a quickly method.

最后,我使用一些php以一种快速的方法解决了这个问题。

for ($i=1; $i<=9999; $i++){
 $my_regex = $i.')';
 mysql_query("UPDATE articles SET title = REPLACE(title,'".$i."', '' ) where title like '%".$i."%'");
}

回答by Andrius Naru?evi?ius

As an alternative, depending on the size of the table, you could do a workaround with substringfunction.

作为替代方案,根据表的大小,您可以使用substring函数进行变通。