首页 > 学院 > 开发设计 > 正文

mysql中替换字符串(正则)

2019-11-06 06:58:11
字体:
来源:转载
供稿:网友

功能:abc<h1>alkdsfjeisalkda</h1>def 替换之后是abcdef

update archives set body = REPLACE(body,substring(body, locate('<h1>', body),locate('</h1>', body)-locate('<h1>', body)+5 ),'')   where id=1

所用函数说明: locate: 

LOCATE(substr,str) 返回子串 substr 在字符串 str 中第一次出现的位置。如果子串 substr 在 str 中不存在,返回值为 0: substringSUBSTR(str,pos,len): 由<str>中的第<pos>位置开始,选出接下去的<len>个字符。replace replace(str1, str2, str3): 在字串 str1 中,当 str2 出现时,将其以 str3 替代。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表