gpt4 book ai didi

MySQL:在字段(正则表达式)中查找所有带有空 anchor 标记的记录并将其删除

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

我有一个表格,其中有一列包含 html 代码。我需要找出所有包含空 anchor 标记的记录,忽略子标记。之后我想删除所有那些空标签。

澄清一下——应该找到这些 anchor ,例如:

<a href="http://www.example.com" target="_blank"></a>
<a href="http://www.example.com"> </a>
<a href="http://www.example.com"><span><strong></strong></span></a>
<a href="http://www.example.com"><span></span></a>

而这些不应该被发现:

<a href="http://www.example.com">something</a>
<a href="http://www.example.com"><span>some text</span></a>

我设法通过此查询获取所有空 anchor (如第一个示例中所示):

select * from table_a where html regexp '<a.*href=".*".*></a>'

但这并没有找到第二个和第三个例子。有人可以帮忙吗?

更新:我想从数据库中删除那些空标签。我摆弄了 MySQLs UpdateXML,但还没有找到解决方案。

最佳答案

我认为最好的方法是使用 xml functions以便从 xml 文档中提取所需的文本节点。

update table_a 
set html = UpdateXML(html, '//a', '')
where ExtractValue(html, '//a//text()') regexp '^[[:space:]]*$'

注意:如果表中的字段包含多个 a 标记,其中一些为空,而另一些为非空,则该字段将不会更新。

关于MySQL:在字段(正则表达式)中查找所有带有空 anchor 标记的记录并将其删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7079253/

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