我是Regex
的新手,几天前开始玩它。但现在我被困在一个string
。
例如:
我有这个字符串 - &gt; <a href="http://somelink.com", example1="", example2="">
我正在尝试Replace
从<a
到>
的所有字符串,但我想保留href
部分和链接。我在https://regex101.com一直在讨论这个问题,但无济于事。我正在尝试的Regex
模式是<a(\s?)(?!.*?href=\".*?\").*?>
。此模式在字符串中找不到任何内容。我正在使用C#
。
非常感谢任何帮助。感谢
更新
实际字符串看起来像
<a href="http://somelink.com", example1="", example2="">
我想删除这部分
, example1="", example2=""
但后来我想保留这部分
<a href="http://somelink.com">
答案 0 :(得分:0)
这可能有效<a(?:.*?)(href=\"(.*?)\").*?>
组(1)= href="..."
和组(2)= link
演示https://regex101.com/r/Yz0kPc/1
添加了更多属性https://regex101.com/r/Yz0kPc/2
答案 1 :(得分:-1)