【发布时间】:2017-11-16 21:14:11
【问题描述】:
如果任何锚标记的 href 属性为空,我将尝试将锚标记值替换为锚的标题值。
喜欢
<a xlink:href="">Lorem Ipsum</a> is simply dummy text of the printing and typesetting industry<a xlink:href ="http://google.com">Google</a>.
如果我尝试使用以下正则表达式:
<a [^>]+>(.*?)<\/a>
然后输出我低于
Lorem Ipsum is simply dummy text of the printing and typesetting industry Google.
它用锚文本值替换了两个锚标记,我需要替换那些 href 属性值为空的锚标记。
我需要像下面这样的输出
Lorem Ipsum is simply dummy text of the printing and typesetting industry<a xlink:href ="http://google.com">Google</a>
【问题讨论】:
-
这会有帮助吗?
<a xlink:href=\"\">(.*?)<\/a> -
不@ramesh 我也添加了正则表达式测试链接,谢谢帮助
-
@PriyankGupta - 您问题中的示例有双引号,而正则表达式只有单引号。对于单引号,请尝试
<a xlink:href=\'\'>(.*?)<\/a> -
为什么不使用 html 敏捷包——更可靠的方法。 html-agility-pack.net/?z=codeplex