tnblog
首页
视频
资源
登录
愿你出走半生,归来仍是少年
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术

c# 正则提取内容,正则取标签内容

5399人阅读 2020/10/17 13:31 总访问:1601723 评论:0 收藏:0 手机
分类: NET

比如要获取font标签里边的内容:<font color='#ff5555' style='font-weight:600'>嘿嘿嘿</font>,可以使用正则放的提取

string summaryitem = "<font color='#ff5555' style='font-weight:600'>嘿嘿嘿</font>";
Match match = Regex.Match(summaryitem, "<font color='#ff5555' style='font-weight:600'>(.*?)</font>");

for (int i = 1; i < match.Groups.Count; i++)
{
    Console.WriteLine(match.Groups[i].Value);
}

效果如下:


正则使用()就可以提取到内容

如果有多个标签都要进行匹配的话可以使用matchs
代码如下:

string summaryitem = "<font>嘿嘿嘿</font>sdfdsf<font>哈哈哈</font>";
MatchCollection matchs = Regex.Matches(summaryitem, "<font>(.*?)</font>");
foreach (Match match in matchs)
{
    for (int i = 1; i < match.Groups.Count; i++)
    {
        Console.WriteLine(match.Groups[i].Value);
    }
}


效果如下:



欢迎加群讨论技术,群:677373950(满了,可以加,但通过不了),2群:656732739

评价