gpt4 book ai didi

mysql在字符串的开头和结尾查找/替换字符,但不在字符串的中间查找/替换字符

转载 作者:行者123 更新时间:2023-11-29 09:01:26 25 4
gpt4 key购买 nike

简短版本:我需要会改变的mysql代码

[href="http://a-random-domain.com"]hyperlink[/href]

进入

<a href="http://a-random-domain.com">hyperlink</a>

  • 不会弄乱域名部分,并且
  • 不会意外转换字段文本中可能出现的任何不相关的“] 实例。
  • 域名每次都是唯一/不同的遇到过。

长版:我正在迁移旧数据库以便与新应用程序一起使用。旧数据库有一个文本字段,其中包含以下内容:

This is a data field with a [href="http://somedomain.com"]hyperlink[/href] and more data and possibly other hyperlinks.

我需要将其更新为标准 html,例如

This is a data field with a <a href="http://somedomain.com">hyperlink</a> and more data and possibly other hyperlinks.

使用 REPLACE 修复 [href= 和 [/href] 非常简单

update table set field = replace(field, '[href=', '<a href=');

但是我被 a href 标签的 "] 右括号绊倒了。数据库中还有其他不应修改的 "] 实例,所以我不能只替换 "]

mysql 是否有某种正则表达式“lookahead”或其他方法来实现此目的?

非常感谢!

最佳答案

http://dev.mysql.com/doc/refman/5.1/en/regexp.html

MySQL 支持仅用于“评估”目的的正则表达式函数。因此,您不能使用它来替换或操作数据。使用高级脚本语言会更好。

关于mysql在字符串的开头和结尾查找/替换字符,但不在字符串的中间查找/替换字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8477487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com