Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Regex在一个模式中查找多个HTML标记_C#_Regex - Fatal编程技术网

C#Regex在一个模式中查找多个HTML标记

C#Regex在一个模式中查找多个HTML标记,c#,regex,C#,Regex,我有一条随机消息(我不知道内容是什么),但我知道它可能包含HTML标记,如和。。。然后我知道没有比这些更多的HTML标记了。 因此,我正在寻找一种模式,它将能够识别和获取粗体标记之间的内容,以及超链接及其内容。 我已经完成了以下代码: string pattern = "(<b>(.*)</b>)|(<a href=.*?>(.*?)<\\/a>)"; Match match = Regex.Match(content, pattern); whi

我有一条随机消息(我不知道内容是什么),但我知道它可能包含HTML标记,如
。。。然后我知道没有比这些更多的HTML标记了。 因此,我正在寻找一种模式,它将能够识别和获取粗体标记之间的内容,以及超链接及其内容。 我已经完成了以下代码:

string pattern = "(<b>(.*)</b>)|(<a href=.*?>(.*?)<\\/a>)";
Match match = Regex.Match(content, pattern);
while (match.Success)

      if (match.Groups[0].Value.Contains("<b>"))
      {
            messageBlock.Dispatcher.Invoke(delegate
            {
                   messageBlock.Inlines.Add(new Run(content.Substring(0, match.Index)));
                   messageBlock.Inlines.Add(new Bold(new Run(match.Groups[1].Value)));
             });
       }
       else if (match.Groups[0].Value.Contains("<a href="))
       }
}
string pattern=“((.*))|(.*)”;
Match=Regex.Match(内容、模式);
while(匹配成功)
if(match.Groups[0].Value.Contains(“”)
{
messageBlock.Dispatcher.Invoke(委托
{
添加(新运行(content.Substring(0,match.Index));
messageBlock.Inlines.Add(新粗体(新运行(match.Groups[1].Value));
});
}
else if(match.Groups[0].Value.Contains(“Try
@”(?s)””)*?\shref\s*=(?:([?))(.*?\2))\s+(?:(?:)(?)(?)(?)(?)(?:(?)(?)(?)(?)(?)(?)(?)(?)(?)(?)(?)(?)(?)(?)(?)(?)(?)*)+)+(?)(?)(?)(?)(?)(?)(?)*?)+)+)(

在哪里

  • 如果Grp1匹配,则找到
    a
    ,否则找到
    b
  • Grp 2忽略
  • Grp 3包含href值(如果grp1匹配)
  • GRP4包含内容


但是对于C#

来说,解析html最好使用

这是评论,不是回答我不能在我的情况下使用它为什么你不能使用它?谢谢!但是它只给出标签的内容,而不是它的href值…我需要两者:$Modified it来获得链接