查找并用新字符串替换REGEX结果

时间:2018-11-02 20:20:34

标签: regex replace find

我想将WP数据库(wp_post field: post_content)中的单个文本字符串替换为10位的pictureID号

pictureid=0001234567(每张照片的后7位数字不同)

为单个值:

sourceids=2518

当我用REGEX查询pictureID号时,似乎返回了我要更改的记录。

SELECT * FROM `wp_posts` WHERE `post_content` REGEXP 'pictureid=000[0-9][0-9][0-9][0-9][0-9][0-9][0-9]'

下一步:如何更改找到到sourceids=2518的那些记录中的pictureID

我确实尝试过

update wp_posts set post_content = replace(post_content, 'REGEXP 'pictureid=000[0-9][0-9][0-9][0-9][0-9][0-9][0-9]'','sourceids=2518'); 

但这不起作用

2 个答案:

答案 0 :(得分:0)

使用REGEXP_REPLACE(pictureid,'000[0-9][0-9][0-9][0-9][0-9][0-9][0-9]',sourceid)

答案 1 :(得分:0)

很抱歉,回复的格式不正确,因此将以这种方式进行

它不起作用,我做了以下工作:测试REGEXP:

选择*从wp_postspost_content的地方REGEXP'pictureid = 0001119708'=工作

SELECT *从wp_postspost_content REGEXP'pictureid = 000 [0-9] [0-9] [0-9] [0-9] [0-9] [0- 9] [0-9]'=工作

尝试将“ pictureid = 000 #######”(其中#是任何数字值,例如:00012345670)替换为此单个值“ sourceids-2518”

SELECT *从wp_postspost_content REGEXP_REPLACE('pictureid = 000 [0-9] [0-9] [0-9] [0-9] [0-9] [0 -9] [0-9]','sourceids = 2518')=无效

相关问题