使用 UDF 在字符串中为 href 添加目标 ='_blank' 的最佳方法

Best way to add target ='_blank' for href in a string using UDF

我在 sql 服务器 2012 中获得了数据,其中包含带有链接的文本 <a href="test/test">test </a> 没有目标我需要为字符串数据添加目标。我需要为此创建一个用户定义的函数。是否有人对此有任何示例代码。

示例文本 -

If you've ever thought one of your text message threads was so good it deserved to be published, you may be on to something.view. <a href="/apple/sdffsd/sdffs">njkhj </a> In future iterations, users will be able to post .<br><br>You may update your email address at any time by going to <a href="/apple/fafasdf/sdfsdf">sdffsd</a>. Our whole goal is to have the reader go through an entire narrative arc in five minutes and consume it in a way that's native to mobile," says Gupta go to <a href="/a/s/sdfsf"> sdfsdf </a> which is one of my favorite books, is told as letters back and forth between the two main

我认为简单的替换就可以解决问题

Declare @String varchar(max) = 'Some large text with a <a href="test/test">link</a> to content'

Select Replace(@String,' href=','_target="blank" href=')

Returns

(No column name)
Some large text with a <a _target="blank" href="test/test">link</a> to content

我们也可以用 SELECT REPLACE(text,'<a','<a target="_blank" '); Go