【问题标题】:how to get all html tags from html file in the list using regular expression如何使用正则表达式从列表中的html文件中获取所有html标签
【发布时间】:2010-09-17 12:47:32
【问题描述】:

文件包含标签为

<html><head></head><body><span class=style32></span>....

我只想要 html 标记,即列表中的 span、head、body。不应该重复。 请帮助我,我是正则表达式的新手。

【问题讨论】:

标签: c# .net regex visual-studio console-application


【解决方案1】:
var tagList = new List<string>();
                 string pattern = @"(?<=</?)([^ >/]+)"
                 var matches = Regex.Matches(file, pattern);

for (int i = 0; i < matches.Count; i++)
                 {

                     tagList.Add(matches[i].ToString());

                 }
                     //to obtain non duplicate list
                     tagList = tagList.Distinct().ToList();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多